Skip to main content

I have a custom object called "Sales targets" this is for tracking the sales of bussiness. The Sales targets id should be updated in related opportunities (one to many) based on region and  Business unit. We are getting a timeout when updating the opportunities due to the volume of related opportunities against a target.  

 

Is there any solution for this, like updating the opportunities in batches , incremental jobs, Custom tables to store the updated data to exclude when selecting the opportunities for updating etc. 

 

 

 

#Salesforce Developer  #Custom Objects  #Salesforce Admin  #CPU Timeouts  #Timeout Issue

1 respuesta
  1. Ayer, 15:09

    Hi Robin, the timeout is because you are updating every matching Opportunity in one synchronous transaction when the target changes, that will always blow the CPU or DML limits at volume. The fix is to move it async and only touch rows that actually need it. 

     

    1. Do the mass update in Batch Apex (or a chained Queueable), not directly in the trigger or flow. Batch processes the opportunities in chunks of 200 in separate transactions, so each chunk stays under limits and the whole set completes without a timeout. 

    2. Filter to a true delta instead of re-updating everything. In the batch query, select only the opportunities that still need the change, for example where the Sales Target lookup is null or different AND region and business unit match. That is your exclude-already-updated idea, but done in SOQL, so no separate custom table to track it. 

    3. Better long-term, flip the direction. Rather than the Sales Target pushing its Id onto thousands of Opportunities, resolve it on the Opportunity side: a before-save flow or trigger on Opportunity sets the Sales Target lookup from that record's own region and business unit when it is created or edited. Then the work is spread across individual cheap saves, and a target change only needs a one-time async backfill of existing records. 

     

    Net: async batch fixes the immediate timeout, the SOQL delta keeps re-runs cheap, and maintaining the link on the Opportunity side avoids the giant bulk update going forward. 

     

    if this helps, please mark it as the Best Answer so it helps the next person, thanks 🙂

0/9000