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
Robert WynterRobert Wynter 

When a formula value changes I want the trigger to update fields

My trigger fires if I edit/save Account only but I want it to fire once the Contract_End__c == Today_10_Trigger__c. The Today_10_Trigger__c is a formula. I'm getting the impression that triggers will not execute on an internal query,if that's the correct phase for a formula field. If this is the case does anyone have a suggestion for me.

Here's my trigger:
 
trigger RenewalUpdates on Account (before insert,before update) {
  
    List<Account > needsUpdate = new List<Account >();  
    
 for( Account accountId : Trigger.new)
 {

  if(accountId.Contract_End__c== accountId.Today_10_Trigger__c && accountId.Record_Type_Hidden__c== 'Agent' && accountId.Status__c == 'Active')
  {
     
     
        // do something here because your field are equal

        accountId.Renewal_In_Progress__c=true;
        accountId.Status__c='Renewal In progress';
        accountId.Approval_Progress__c='Up For renewal';        
     
        needsUpdate .add(accountId);
        System.debug('Test=============');
  }
}

}

 
Mahesh DMahesh D
Hi Robert,

You can achieve this using the Batch Apex.

Batch Apex
A Batch class allows you to define a single job that can be broken up into manageable chunks that will be processed separately.

When to use Batch Apex
One example is if you need to make a field update to every Account in your organization. If you have 10,001 Account records in your org, this is impossible without some way of breaking it up. So in the start() method, you define the query you're going to use in this batch context: 'select Id from Account'. Then the execute() method runs, but only receives a relatively short list of records (default 200). Within the execute(), everything runs in its own transactional context, which means almost all of the governor limits only apply to that block. Thus each time execute() is run, you are allowed 150 queries and 50,000 DML rows and so on. When that execute() is complete, a new one is instantiated with the next group of 200 Accounts, with a brand new set of governor limits. Finally the finish() method wraps up any loose ends as necessary, like sending a status email.

Sample Batch Apex
1) Start Method is automatically called at the beginning of the apex job. This method will collect record or objects on which the operation should be performed. These record are divided into subtasks & passes those to execute method.

2) Execute Method performs operation which we want to perform on the records fetched from start method.

3) Finish Method executes after all batches are processed. Use this method to send confirmation email notifications.

Please go through the below links:

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_batch_interface.htm

https://developer.salesforce.com/docs/atlas.en-us.apex_workbook.meta/apex_workbook/apex_batch_intro.htm

http://www.infallibletechie.com/2013/01/simple-batch-apex-example-in-salesforce.html

http://www.salesforcetutorial.com/what-is-batch-apex/

http://www.salesforcetutorial.com/running-batch-apex-example/

https://www.youtube.com/watch?v=PmvpMakxpm8

http://blog.shivanathd.com/2013/01/how-to-write-batch-class-in.html

http://amitsalesforce.blogspot.com/2016/02/batch-apex-in-salesforce-test-class-for.html

https://www.minddigital.com/how-to-call-batch-apex-by-scheduler-class-within-salesforce/


Please do let me know if it helps you.

Regards,
Mahesh