Monitoring Salesforce API Calls, Storage Usage, Outgoing Emails, and Other Resources and Limits

Like many other cloud platforms, Salesforce monitors and limits resource usage on its instances (orgs). User count is the most obvious example, as it drives monthly customer charges. However, there are about 50 other limited resource types*, such as the number of scratch orgs, dashboards, mass emails sent, and others.

Organizations that use Salesforce as a ‘vanilla CRM’ typically do not need to worry about anything other than user counts and data storage. However, this changes when additional Salesforce components are added, such as quoting, order processing, billing, or integrations with third-party systems.

This post provides insights into monitoring resource usage and offers solutions for addressing issues when limits are reached.

* Based on the return of v50.0 of the limits API

API Calls

API calls are the only integration interface to Salesforce. They are used by third-party tools and add-ons such as backups, reporting tools, etc. as well as custom integrations. API calls are a metered resource and have 24 hours’ limits. When the limits are exhausted, Salesforce becomes inaccessible via the API until usage counts are reset.

In our experience, the most common problem with exhausting API limits by far is inefficient programming. Please take a look at his section below for possible remedies.

Checking Your Limits

API limits are dependent on many factors (type of org, edition, number of users, additional API purchases, etc.) and can be checked in Setup → Company Settings → Company Information:

Salesforce API limits information
Salesforce API limits information

Obtaining Detailed Information

API usage consumption details are available from the API Usage Last 7 Days report, which is only available in the classic experience. To access the report:

  1. Switch to classic user experience (user profile icon → Switch to Salesforce Classic).
  2. Choose Reports from the menu bar.
  3. Navigate to the Administrative Reports folder.
  4. Select the API Usage Last 7 Days report.
Salesforce 'API Usage Last 7 Days' report
Salesforce ‘API Usage Last 7 Days’ report

The limits API call returns fewer details, i.e. only information for the last 24 hours:

   "DailyApiRequests": 
       { 
         "Max": 375000, 
         "Remaining": 270012,
              ... individual application statistics follow ...
        }
 

Building a Better Client

Salesforce REST API returns the current usage with every response in a Sforce-Limit-Info response header: Sforce-Limit-Info: api-usage=1212/15000 The code below is an example of how to retrieve the value in Java using Apache HttpClient (error handling omitted for simplicity):

String apiUsage = Arrays.stream(response.getHeaders("Sforce-Limit-Info"))
    .filter( h -> h.getName().equals("Sforce-Limit-Info"))
    .findFirst()
    .get()
    .getValue();

... parse the apiUsage string and take action ...
 

For example, this strategy is implemented by the Nextian Network Monitoring Integration, which uses APIs to pull information from NMS/RMM/Observability systems into Salesforce..

Setting Up Alerts

It is possible to set up API usage alert notifications via Setup → Environments → Monitoring → API Usage Notifications (more information). At Nextian, we recommend setting API notification thresholds as follows:

30-40%Normal level allowing for daily spikes such as extra backups, data warehouse refreshes, etc.
50%Warning level — system administrators need to examine what is happening
80%Critical — usually triggers an action to suspend offending user or software package
 

Overcoming API Limits

  1. Optimize programming — ‘bulkify’ requests to Salesforce (i.e., consolidate multiple calls into fewer ones), reduce number of calls by decreasing polling frequencies, etc.
  2. Purchase more API licenses from Salesforce — this should only be done once options in #1 above have been exhausted.
ImportantSalesforce event log files can be helpful troubleshooting API usage, as they provide detailed information down to individual calls.
 

Storage

Salesforce storage is split into object storage (similar to a relational database table row storage) and file storage (similar to relational database blobs).

The smallest record size in Salesforce is 2Kilobytes regardless of number of fields, therefore storage optimization should start with small but numerous objects.
 

Checking Your Limits

Current storage limits are available (just like the API limits) in Setup → Company Information.

Obtaining Detailed Information

Detailed storage usage (with per object/row count breakdown) is available in Setup → Data → Storage Usage.

Optimizing Storage Usage

  1. Implement a retention policy to delete or archive unneeded records. There are off-the shelf archive packages such as ownBackup Archiver; a backup solution or a replication of Salesforce storage to a relational database can be used to the same effect.
  2. Consider external file storage alternatives like Box.com when storing large volumes of files.
  3. Clean up ‘orphaned records’, i.e., records for objects that could not be set up as master-detail and do not get deleted along with their ‘master’ records.
  4. Look at the detailed storage information and optimize the schema, e.g., replace junction objects with lookups wherever possible.
  5. As a last resort — evaluate purchasing additional storage from Salesforce.

Outgoing Emails

There are three types of email limits in Salesforce, per each origination type (described here). Unfortunately, the usage can be only retrieved via the limits API. For example, for emails sent from APEX code as notifications (‘SingleEmail‘), the limits API returns:

"SingleEmail": {
  "Max": 1000,
  "Remaining": 920
}
 

Usage limits can pose challenges for organizations sending high volumes of notifications to external contacts (internal emails do not count against these limits). Typically, business processes determine what needs to be sent, so the only workaround is to purchase additional email capacity from Salesforce or integrate with third-party email sending tools.

Limits API

In essence, Limits API it is a single REST endpoint returning all limits and current usage as JSON data:

<your Salesforce org URL>/services/data/v50.0/limits
 

It is accessible via any tool capable of working with REST endpoints such as Postman. Detailed information about the API is available here.

Event Monitoring

In addition to the Limits API, Salesforce provides Event Log Files (ELFs) containing records of operations (‘events’) happening on orgs. More than 50 types of events are logged including logins, logouts, object access, data downloads and others — the detailed list is available here.

 
ImportantProduction orgs often log only login and logout events — in that case, full logging may require an extra purchase from Salesforce.
 

Log files are stored as CSV (comma separated values) files. The log files are only accessible via the API, although tools such as Splunk or Salesforce own Event Monitoring Analytics automate the process of their retrieval and parsing (which is a bit convoluted as shown below).

The list of Event Log Files can be retrieved using the following SOQL query in the Developer Console:

SELECT
  Id,                /* event log file id needed later for content retrieval */ 
  EventType,         /* type of events contained in the file */
  LogFileFieldNames, /* event type specific columns in the file */
  LogFileFieldTypes, /* types for LogFileFieldNames */
  LogDate            /* log file date */
  /* LogFile field contains blob with file CSV content */
FROM
  EventLogFile
 

The contents can be retrieved using tools like cURL:

curl --compressed "https://<org instance>/services/data/v50.0/sobjects/EventLogFile/<id from query above>/LogFile" -H "Authorization:Bearer <user token>" -o LogFile.csv
 

Once downloaded, the file can be further processed.

Conclusions

Like many cloud platforms, Salesforce monitors and enforces resource usage limits. In complex implementations with numerous add-ons and integrations, excessive resource usage can result not only in unnecessarily high ownership costs but also in making an org temporarily unavailable until the limits are reset. Fortunately, various strategies and workarounds can help mitigate these limitations.

Contact us today to find out how we can help you!

Thank you for contacting Nextian. Your request was successfully submitted, we will get back to you within two working days.

BY INDUSTRY

Cloud Infrastructure Providers

Cloud Software Companies

Managed Service Providers

Communications Service Providers

BY ROLE

CEO / Owner

CRO / VP Sales

CFO / VP Finance

COO / VP Operations

CPO / VP Product

CIO / VP IT

Product Management

Plan, launch and manage your product offerings throughout their entire lifecycle.

CPQ & Sales

Quickly create accurate quotes for complex products, subscriptions and add-ons

Order Management

Ensure faster, consistent order delivery with tasks, workflows and automation

Service Management, Support & Monitoring

Retain and upsell customers with comprehensive account intelligence, support, monitoring, analytics

Customer Portal

Empower your customers with 24/7 self-service, support and on-line ordering

NEXTIAN PLATFORM

Platform Overview

Billing Integration

Network Monitoring Integration

Reporting & Analytics