Skip to main content The new Salesforce certifications experience is live! Visit Trailhead Academy to explore your new certifications homepage.
Hi Eveyone,

 

I have a class which is scheduled on daily basis.This class will check a date field(contract date) in all opportunities and if this date is today, it will update a checkbox field in all those opportunities.

 

Now this checkbox field will fire a trigger which will clone the same opportunity and all its child opportunities.

 

Now, say i have 10 opps for which this scheduled class is executing and for each of these opps more than 30 child opps are there which will also get cloned from trigger.

 

Now, this job is not working in prod showing as Apex cpu time limit exceeded.

 

Please suggest which approach should i follow for this scennario.
1 answer
  1. Sep 2, 2019, 5:56 AM
    Hi Kamesh, 

     

    If you're hitting CPU limits for 300 child opportunities, then your trigger is probably not very optimised. You should start by making sure your code can handle bulk operations. 

     

    You can also take the lazy approach and process each opportunity in its own Queueable apex thread. This will give each opportunity its own clean transaction, but there are additional limits on how many Queueables you can have queued at any one time. 
0/9000