You need to sign in to do that
Don't have an account?
Andrew Hoban 6
CPU Time-Out on Trigger isBefore
Hi,
I am getting a CPU Time-Out error message with reference to the trigger below.
The only records I want to be triggered are records that match the IF criteria, however all records will be processed within the loop.
When I add 800 test records that dont even meet the critera, im getting the CPU error.
What would be the best practice to only process the records that meet the criteria beofore entering the loop?
I am getting a CPU Time-Out error message with reference to the trigger below.
The only records I want to be triggered are records that match the IF criteria, however all records will be processed within the loop.
When I add 800 test records that dont even meet the critera, im getting the CPU error.
What would be the best practice to only process the records that meet the criteria beofore entering the loop?
trigger accountTrigger on Account (before insert, before update, after insert, after update) { if(Trigger.isBefore) { if(Trigger.isInsert) // Run only BEFORE Insert { } if(Trigger.isUpdate) // Run only BEFORE update { } if (Trigger.isInsert || Trigger.isUpdate) { for(Account acc: Trigger.new){ if (acc.EFCAIS__Status__c != NULL && acc.PersonBirthdate != Null){ academyCriteriaHandler.calculateAgeInformationCriteria(Trigger.new, Trigger.oldMap, Trigger.newMap); } } } }
I found few links that could be of help in debugging where the issue occurring from below are the links:
Apex CPU Limit Exceeded.
https://help.salesforce.com/apex/HTViewSolution?id=000232681&language=en_US
https://developer.salesforce.com/page/Apex_Code_Best_Practices
http://www.jitendrazaa.com/blog/salesforce/batch-apex-first-error-apex-cpu-time-limit-exceeded/
Hope this helps you!
If this helps you please mark it as solved.
Thanks and Regards
Anutej
You are writing the wrong code in the trigger. Please follow the below code for your functionality.
Please let me know if this code still giving you the CPU time error.
Please also check that you don't have any other trigger on the same Account Object. Maybe you have any other process builder or workflow that is updating the same account record again and again.