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
Joshua Anderson 17Joshua Anderson 17 

Update via Process Builder on roll up.

So I have two rollup summaries (Total_Opportunities_Won__c && Active_Opportunities__c) that feed into the Account object from the opportunities object. I was trying to update a picklist (Customer_Type__c)
  • Former Client = Total_Oppotunities_Won__c >= 1 && Active_Opportunities__c = 0
  • Current Client = Total_Oppotunities_Won__c > 0 && Active_Opportunities__c = 1
  • Prospect = Total_Oppotunities_Won__c = 0 && Active_Opportunities__c = 0
I couldn't figure out how to update field via process builder so I turned this field into a formula(text). It looks like they are now wanting a workflow/process builder to update any contacts associated with that account so I tried to schedule an Apex Class to run nightly to update this information. I was able to save the Apex but when I scheduled this Apex to test nothing seemed to update. Was wondering if anyone had any idea what I might be donig wrong in my apex class or any recommendations? 
 
global class DailyContactProcessor implements Schedulable {

    global void execute(SchedulableContext ctx) {
        List<Contact> myList = [Select Id, Contact_Type__c from Contact where Account_Status__c = 'Former Client'];
        
        if(!myList.isEmpty()) {
            for(Contact l: myList) {
                l.Customer_Type__c = 'Former Customer';
            }
            update myList;
        }
    }
}
In the Apex Class I created a formula field (Contact.Account_Status__c) which pulls from Account.Customer_Type__c. It is supposed to pull a list of all contacts that show 'Former Client' and then update 
 
Ashish DevAshish Dev
You can use debug log (through system.debug statements) to find the problem.
But I would recommend you to write a batch class instead of schedulable for serial processing of all the records.

Let me know if this helps you.