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 

populate a date field off a roll up summary

I am trying to update a date field on the Account object when two roll up summaries (Total_Opportunities_Won__c & Active_Opportunities__c) enter 0. Currently our process is that we have two roll up summaries that feed from the Opportunity object and then we have 3 scheduled apex classes to update the status. What I am needing to accomplish is a way to update a date field on the Account object when both the roll up summaries equal 0. Then if the roll up summary for Active_Opportunities__c increases to 1 or greater to put todays date. Was wondering if someone might be able to help the newbie with this? 
global class DailyAccountProcessorProspect implements Schedulable {

    global void execute(SchedulableContext ctx) {
        List<Account> myList = [SELECT Active_Opportunities__c,Id,Total_Opportunities_Won__c FROM Account WHERE Total_Opportunities_Won__c = 0 AND Active_Opportunities__c = 0];
        
        if(!myList.isEmpty()) {
            for(Account l: myList) {
                l.Customer_Type__c = 'Prospect';
            }
            update myList;
        }
    }
}
global class DailyAccountProcessorFormer implements Schedulable {

    global void execute(SchedulableContext ctx) {
        List<Account> myList = [SELECT Active_Opportunities__c,Id,Total_Opportunities_Won__c FROM Account WHERE Total_Opportunities_Won__c >= 1 AND Active_Opportunities__c = 0];
        
        if(!myList.isEmpty()) {
            for(Account l: myList) {
                l.Customer_Type__c = 'Former Customer';
            }
            update myList;
        }
    }
}
global class DailyAccountProcessorCurrent implements Schedulable {

    global void execute(SchedulableContext ctx) {
        List<Account> myList = [SELECT Active_Opportunities__c,Id,Total_Opportunities_Won__c FROM Account WHERE Total_Opportunities_Won__c >= 1 AND Active_Opportunities__c = 1];
        
        if(!myList.isEmpty()) {
            for(Account l: myList) {
                l.Customer_Type__c = 'Current Client';
            }
            update myList;
        }
    }
}



 
rajat Maheshwari 6rajat Maheshwari 6

Hi Joshua,

Why you have create 3 scheduled apex class ? instead you should write 1 class. and Could you please let me know, what value you want to give on date field ?

Thanks
Rajat maheshwari
rajatzmaheshwari@gmail.com,

 

Joshua Anderson 17Joshua Anderson 17
Rajat, 

I was looking for it to fill the date field with Date.today(); Mainly once the values of the roll up summary for Active_Opportunities__c goes from 1 or higher to 0 I want it to stamp that field with the current date. From there I am going to add that date field to the former scheduled apex that it changes it 120 days after that time stamp. In terms of the 3 scheduled apex I wasn't sure how to combine them so I did what I knew. I figured that I would try and combine them eventually but wanted to get this functionality working. Do you know btw how to make these run every 15 minutes?