function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Neha Jain 136Neha Jain 136 

Roll up summary field on account won't trigger field change on opportunity object

Hi

I would like to update the opportunity stage to "transacting" when a roll-up summary field on the account (Total Transaction) become =>2 which is getting information from bill object. I tied many ways but unable to change stage. 

I tried below ways none of them are working.
1) Roll up summary field won't trigger workflow and process builder
2) Created a checkbox on opp which turns "true" when total transaction meet criteria, But still won't change stage through Process Builder/workflow. 

Please help!!!
CloudalyzeCloudalyze
Hi Neha,

please check with the below Trigger Handler 

public class ChangeOpportunityStage {
    public static void changeStage(List<Opportunity> oppList) {
        set<id> oppId = new set<id>();
        for(Opportunity opp:oppList) {
          oppId.add(opp.AccountId);
        } 
       List<Account> accList = [Select Total_Transaction From Account WHERE id =:oppId];
        set<id> OpportId = new set<id>();
        for(Opportunity oppObj : oppList) {
            OpportId.add(oppObj.id);
        }
        List<Opportunity> oppLists = [Select StageName From Opportunity where id =:OpportId];
         List<Opportunity> uppOppList = new List<Opportunity>();
        for(Opportunity oppObject :oppLists){
            if(accList[0].Total_Transaction > 2) {
              oppObject.StageName = 'transacting';
                uppOppList.add(oppObject);
            }
        }
         update uppOppList;
    }
}

and check with the opportunity trigger 

trigger OpportunityTrigger on Opportunity (After insert,After Update) {
ChangeOpportunityStage.changeStage(Trigger.new);
}

Please let us know if it is workning or not.