You need to sign in to do that
Don't have an account?
Upendra
Update a record after getting governor limit exceed exception
Hi Guys,
I have a custom object called "AsyncProcessJob", this object tracks all my async process in my system. I have to insert a record into the object then it executes some logic depending on some other field values. If the logic updates successfully then it sets the status of the record as "Success", if it fails then "Failed".
This logic fails when salesforce governor limit exceeds, in such cases it's unable to update the status as the execution stops completely.
So, I want to know is it possible to update the record after the governor limit exceeds.
I have a custom object called "AsyncProcessJob", this object tracks all my async process in my system. I have to insert a record into the object then it executes some logic depending on some other field values. If the logic updates successfully then it sets the status of the record as "Success", if it fails then "Failed".
This logic fails when salesforce governor limit exceeds, in such cases it's unable to update the status as the execution stops completely.
So, I want to know is it possible to update the record after the governor limit exceeds.
Yes/No :) ,we have Limits Class in salesforce which can be used to findout the current usage of these limits and margin left.
so you can code such that if current SOQLs used are already 100, don't perform any SOQL operation further and log a warning in the custom object, which may be possible in only certain scenarios.
Please see below links:
http://www.salesforcehacker.com/2014/05/that-which-doesnt-limit-us-makes-us_20.html
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_limits.htm
There're some design patterns can help you out. One simple solutions is to put the update of AsyncProcessJob into the @future method.
Salesforce will not allow any actions once governor limits are hit and Rolls back all the operations performed till that time in the same transaction.
so updating record after the governor limit exceeds is not possible but before hitting the limit is possible.
Work around is before hitting the limits i.e in case of SOQL 101 error, caputure the current usage (using Limits class) of limits before performing any SOQL operation and check if it reached 100 via apex code. once it reacched 100 can log a warning and stop performing any further SOQLs in certain scenarios only.
@Just In You, Already using future job for process for doing the operation. You pointed out some design pattern, can you please mention here.