You need to sign in to do that
Don't have an account?
sfdc dev 2264
System.LimitException: Apex CPU time limit exceeded help needed
Hi ,
I have a trigger where i am getting the following exception often
System.LimitException: Apex CPU time limit exceeded
Please help me how to fix this issue
Kindly help me pls
Thanks in Advance
I have a trigger where i am getting the following exception often
System.LimitException: Apex CPU time limit exceeded
Please help me how to fix this issue
MY TRIGGER : trigger AccconRshipUpdate on Contact (after insert, after Update,after delete,after undelete){ try{ Trigger_Status__c ts = Trigger_Status__c.getValues('AccconRshipUpdate'); if(ts.Active__c) { if ((trigger.isafter && trigger.isInsert) || (trigger.isafter && trigger.isUpdate)) { accConRshipUpdateonContacts.AccContactInsUpdate(trigger.new); } if ((trigger.isafter && trigger.isInsert) || (trigger.isafter && trigger.isUpdate) || (trigger.isafter && trigger.isdelete)|| (trigger.isafter && trigger.isUndelete)) { Contact[] cons; if (Trigger.isDelete) cons = Trigger.old; else cons = Trigger.new; RollupofCLcontactsHandler.CountNumofContacts(cons); } } }catch(Exception e){ System.debug('Error Occured From AccconRshipUpdate Trigger: '+e.getMessage()); } }
Kindly help me pls
Thanks in Advance
Pls help me what is wrong in it
These are the 2 apex classes referred n that above trigger
Kindly help me to fix this issue
Thanks
into You should put invariants outside of the loops. For instance
is invariant, giving always the same result during the whole for() loop. You could have Boolean nonEmptyAirportCode=(mapAirportcode.size() > 0) then replacing your test into "if(nonEmptyAirportCode)". It consumes less cpu to do less evaluations.
Same for "mapContact.get(accCon.ContactId)" : you evaluate this 7 times while you could evaluate it only once
You can make your code simpler too. With less instructions, it is sometimes quicker. For instance, instead of
You could write Not much reducing cpu, mostly reducing heap and apex code size (which is another governor limit)
This code is too much complex while this one gives the same result. In fact, the best would be to keep the test and construct another list to update only accounts that have changed. This will reduce the quantity of cascade triggers and cascade code executed, improving performance and CPU