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
Rahul Kainth 14Rahul Kainth 14 

Governor limit refresh on change of trigger context

Hi. I have a question regarding apex trigger context. Suppose If I want to update account in after update context, and right after updating account, I want to update contact in account trigger only. Now Contact trigger will run. The question is as trigger context is changed from account to contact, will it refresh governor limit as well?
VinayVinay (Salesforce Developers) 
Hi Rahul,

As per my understanding, this would refresh the limit.  However, I would suggest replicating the scenario and check debug logs that can help you and give more details on limits.

https://developer.salesforce.com/docs/atlas.en-us.salesforce_app_limits_cheatsheet.meta/salesforce_app_limits_cheatsheet/salesforce_app_limits_platform_apexgov.htm

Thanks,
leonardokipperleonardokipper
Hi Rahul, you cannot update the same record on after context trigger. To do this you need to call a future method.
If you use a future method, it will be a new transaction with new governor limits.

If you implement the account update on before context trigger and then the contact update on after context, it will be the same transaction context and will not refresh your governor limits. 
Andrew GAndrew G
As per Leonardo comment, it would count as one transaction and the limits would not be refreshed.  Save order of execution would kick in and even though you are updating another record, they all count to the same transaction.

And if we check this reference:
Context Variable Considerations | Apex Developer Guide | Salesforce Developers (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_context_variables_considerations.htm)
Even though it is possible to update the original object in the "after update" event, it is not considered best practice as it could cause an infinite loop

regards
Andrew