Blog post

How to earn Reputation Point on Ask Question in community in Salesforce?

Posted on Oct 07, 2015
by Prabhat Gangwar
in Technology
with 0 comments

Requirement: When any community user  ask any question then increase  Reputation Point  of that Community User how ?

Solution: Using Helper Class

Code : 


Trigger :
trigger IncreasePointsOfCommunityUserAskQues on Question (after insert) {
  IncreasePointsOfCommunityUserHelper.IncreasePointsOfCommunityUserExecute(trigger.new ,trigger.isafter ,trigger.isinsert); 
 }




Helper Class:
public class IncreasePointsOfCommunityUserHelper{
    public static void IncreasePointsOfCommunityUserExecute(list<question> triggernew, boolean isafter, boolean isinsert){     
        if(isafter)
            IncreasePointsOfCommunityUser(triggernew,isafter,isinsert);

    }
    public static void IncreasePointsOfCommunityUser(list<question> triggernew, boolean isafter, boolean isinsert){
        set<id> CummunityUserID = new set<id>(); // hold id of community user
        list<NetworkMember> updatelistofPoint = new list<NetworkMember>(); // updatelistofPoint of cummunity user
            if(isInsert){
                for(Question ques : triggernew){
                    if(ques.Title != null){
                        CummunityUserID.add(ques.CreatedById);
                    }
                }
            }
        for(NetworkMember userpoint : [SELECT MemberId,ReputationPoints FROM NetworkMember where MemberId in : CummunityUserID ]){
                userpoint.ReputationPoints = userpoint.ReputationPoints+1;
                updatelistofPoint.add(userpoint);
        }
            if(updatelistofPoint.size()>0){
                update updatelistofPoint;
            } 
    } 
}
      
 


0

Leave your comment

Leave your comment