0

I need your advice to implement a procedure to monitor salesforce governor limit status such as CPU limit, Heap size and warn the administrator before it is reached the maximum threshold and throw as salesforce error

  • Problem context:

we got a strange situation, the data loader updates less than 1000 records and we maintain the batch size 1 to minimize the resource cost. This process will update data in 2 objects .user update bill information from data loader. This update happens in the bill object's update trigger. then it gets bill line item (Detail object of the bill ). each line item has a related service item (separate customer object ). there are 2 update routines to update Service items - update cheque detail of the related bill - updates service item status. there is an if-else condition These 3 objects have lot of validation rules, process builder and flows

  • Issue:

An issue was reported by the client some of the SI statuses were not updated but cheque detail updated correctly. when we re-run the update for a subset of bills which were failed, then it worked perfectly. hence, we come to a conclusion there is no data issue.

when we escalated this situation to salesforce and got feedback. it says there is no error on the server but CPU cost gets close to the limit during the process.

  • 1
    Can you please explain why you don't simply allow the limits to be hit and have notification emails sent to the admins? – Phil W Feb 13 at 9:15
  • Hi @PhilW, As limit exceptions are not catchable, how do you do that? – Keith C Feb 13 at 10:20
  • Hi,, I updated the issue with further detail – chamika Feb 14 at 7:25
2

I wrote a custom Exception framework that I used to gracefully break from governor limits before I hit them, which I outlined in this answer. The only downside is that you have to manually call the framework periodically in order to gain this benefit, which means scattering method calls throughout your code. It's certainly possible to build such a framework, but it's not very elegant because of the manual call-requirement. Because of this, I also created an Idea to ask salesforce.com to implement something like this as a standard feature (go vote!).

  • 1
    I added an alternative idea. – Phil W Feb 13 at 12:09
  • Hi sfdcfox , your 1st idea is closely aligned with my requirement , thanks – chamika Feb 14 at 7:27
0

I had developed an aura component some time back which displays the org limits. You can refer to my blog and use a similar concept to notify the admin. The key here is to use the OrgLimits class which was introduced by Salesforce in Summer 19.

https://salesforcespace.blogspot.com/2019/06/org-limits-lightning-component.html

  • 3
    OrgLimits gives info on "Salesforce API limits"; per transaction information is provided by the Limits class. – Keith C Feb 13 at 10:26
  • thanks, I'll check on this – chamika Feb 14 at 7:27
-1

You can build a client app or use CURL to call the limit REST API:

curl https://instance.salesforce.com/services/data/v47.0/limits/ -H "Authorization: Bearer token"
  • 1
    This won't help with CPU limits and heap size limits because these are per-session. – Phil W Feb 13 at 9:14
  • Good point Phil, I admit that I misread that part of the question :( – POZ Feb 13 at 10:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.