solution for apex cpu time limit exceeded exception
Currently we are using informatica data loader which loads a bunch of contacts in salesforce using bulk api. The underlying trigger on contact would create account, contact and other related objects. When we use the bulk api on the data load , we get apex cpu time limit exceeded. This happens only if we use the bulk api and if we use regular upload, it works. Is there anything which we need to do for bulk api or how can we get past the cputime limit exceeded error?
CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY:EnrollmentrxRx.ContactCustomerPortal: execution of BeforeUpdate caused by: System.LimitException: Apex CPU time limit exceeded Class.ApplicationTriggerHandler.applicationAfter: line 116, column 1 Class.ApplicationTriggerHandler.afterUpdate: line 51, column 1 Class.TriggerFactory.execute: line 71, column 1 Class.TriggerFactory.createHandler: line 32, column 1 Trigger.ApplicationTrigger: line 13, column 1:—
Review your code and optimize it. May not be the answer you want to hear but it may be what is required
There is no specific setting that will increase CPU time for bulk api.
What is happening is that when you schedule data load through bulk it put system under stress and it is not able to finish the given task in appropriate time and so throws error Apex CPU time limit exceeded.
To avoid CPU limit you need to optimize your code. Here are few tips:
- Check the trigger execution and note the required time.
- With the help of developer console you can figure out where CPU time is spent and then target the area which most CPU costly.
- try and optimize those costly code blocks
- Note for optimization of trigger you can use anomalous block to fire trigger