Tips to Avoid Hitting Salesforce Governor Limits

Salesforce is amazing. It's powerful, flexible, and makes managing customer relationships a breeze. But here's the kicker - those API limits? Yeah, they can sneak up on you fast. One day your integration is running smooth, and the next, boom - API limit hit, everything grinds to a halt.

Sound familiar? If you're using Salesforce heavily, especially with custom integrations or third-party apps, API limits can become your worst nightmare. But don't worry. There are plenty of smart, effective ways to sidestep this problem. Let's dive into the best tips and strategies to keep you far, far away from hitting those dreaded Salesforce API limits.

Understand What Salesforce API Limits Are

Before we get into the tactics, you need to understand what you're dealing with. Salesforce imposes a daily API call limit based on your edition and the number of user licenses. For example:

  • Enterprise Edition: 100,000 calls per day or 1,000 per user.
  • Unlimited Edition: 1,000,000 calls per day or more depending on license count.

An API call is any time you interact with Salesforce externally - like through a connected app, integration, or custom code that pulls or pushes data. Think of it as a toll booth. Each time you pass through, you pay with one API call.

Once you hit the limit, no more traffic until the counter resets. That usually means major delays, angry customers, and a lot of stress.

Monitor API Usage Regularly

Let's be honest: if you're not keeping an eye on your usage, you're setting yourself up for failure. Salesforce provides built-in tools to help monitor API usage:

Use System Overview:
  • Go to Setup > System Overview.
  • You'll see a daily API request limit and how much of it has been used.

Create a Custom Report or Dashboard:

You can also track API usage using Event Monitoring (available in Enterprise and up) or via the REST API like this:

GET /services/data/v57.0/limits
Authorization: Bearer YOUR_ACCESS_TOKEN

This returns all your current limits and how much you've used. Set up alerts using tools like Salesforce Shield, Datadog, or New Relic to warn you when usage gets close to the cap.

Optimize Data Queries

Querying too much data at once is a fast way to drain your API budget. Do more with less.

Only Fetch the Fields You Need

Instead of this:

SELECT Id, AccountId, AssistantName, AssistantPhone, Birthdate, CreatedById, CreatedDate, CurrencyIsoCode, DeceasedDate, 
    Department, Description, DoNotCall, Email, EmailBouncedDate, EmailBouncedReason, Fax, FirstName, Gender, GenderIdentity, 
    HasOptedOutOfEmail, HasOptedOutOfFax, HomePhone, IndividualId, IsDeleted, IsEmailBounced, IsPersonAccount, IsPriorityRecord, 
    Jigsaw, JigsawContactId, LastActivityDate, LastCURequestDate, LastCUUpdateDate, LastModifiedById, LastModifiedDate, 
    LastName, LastReferencedDate, LastViewedDate, LeadSource, MailingAddress, MailingCity, MailingCountry, MailingCountryCode, 
    MailingGeocodeAccuracy, MailingLatitude, MailingLongitude, MailingPostalCode, MailingState, MailingStateCode, MailingStreet, 
    MaritalStatus, MasterRecordId, MiddleName, MobilePhone, Name, OtherAddress, OtherCity, OtherCountry, OtherCountryCode, 
    OtherGeocodeAccuracy, OtherLatitude, OtherLongitude, OtherPhone, OtherPostalCode, OtherState, OtherStateCode, OtherStreet, 
    OwnerId, Phone, PhotoUrl, Pronouns, RecordTypeId, ReportsToId, Salutation, SequenceInMultipleBirth, Suffix, 
    SystemModstamp, Title
FROM Contact

Use this:

SELECT FirstName, LastName, Email FROM Contact

It's like ordering a drink at a bar. Don't ask for the whole menu if you only want a Coke.

Use Filters Wisely

Limit your queries with smart WHERE clauses:

SELECT Name FROM Account WHERE CreatedDate = LAST_N_DAYS:30

This ensures you're not pulling 10 years of data when you only need 30 days.

Use Bulk API Whenever Possible

Salesforce has different APIs-REST, SOAP, and Bulk. The Bulk API is designed for large volumes of data. It consumes fewer calls and runs faster for large data sets.

Let's say you need to update 10,000 records.

If you use REST API:

  • That's potentially 10,000 API calls.

If you use Bulk API:

  • That's 1 call to submit the batch, and maybe a few more to monitor status.

Example Using Bulk API:

POST /services/async/57.0/job

Create a job, upload batches, and boom - you've saved thousands of calls.

Implement Caching Where Appropriate

Why ask Salesforce for the same data every 10 minutes?

Use caching for data that doesn't change often. Things like:

  • Country or state lists
  • Product catalogs
  • User permissions

Use local storage or tools like Redis, Memcached, or even browser-level caching if it's for a frontend app.

Batch Your Operations

Instead of sending one request per operation, bundle them.

Salesforce lets you combine multiple calls into one with Composite API or Batch Apex.

Example: Composite API Call

POST /services/data/v57.0/composite
{
  "compositeRequest": [
    {
      "method": "POST",
      "url": "/services/data/v57.0/sobjects/Account",
      "referenceId": "refAccount",
      "body": {
        "Name": "New Account"
      }
    },
    {
      "method": "POST",
      "url": "/services/data/v57.0/sobjects/Contact",
      "body": {
        "LastName": "Doe",
        "AccountId": "@{refAccount.id}"
      }
    }
  ]
}

Two birds, one call.

Use Streaming or Pub/Sub API for Real-Time Data Needs

Need real-time updates? Don't poll Salesforce every 5 minutes. That's API suicide.

Use Streaming API or Pub/Sub API to subscribe to events and get notified when something changes.

Think of it like getting push notifications instead of checking your phone every 2 minutes.

Offload Work to Third-Party Systems

If you've got heavy processing or reporting needs, consider pushing data into a separate system like:

  • AWS
  • Snowflake
  • Google BigQuery

Once data is out of Salesforce, you can crunch it, filter it, and analyze it without eating into your API calls.

Reevaluate Third-Party Integrations

You might have apps installed that are eating API calls like they're at an all-you-can-eat buffet.

Go into Setup > Installed Packages and check the API usage per app. Some might be:

  • Polling too often
  • Pulling too much data
  • Poorly written

Talk to vendors, tweak their configurations, or replace them with more efficient alternatives.

Use Outbound Messaging and Platform Events

Need to send info to an external system when something changes?

Instead of writing Apex or polling, use Outbound Messaging or Platform Events. They use fewer resources and don't cost API calls in the same way.

Set API Limits Per User or App

Protect yourself by setting user-specific limits.

Use Named Credentials or custom middleware that rate-limits requests from heavy users or rogue apps.

If an app goes haywire, you don't want it dragging down your whole org.

Avoid Frequent Logins

Did you know each login counts as an API call? Instead of logging in every time you make a call, store the session token and reuse it until it expires. Most libraries (like JSforce, Salesforce DX, and Python's Simple-Salesforce) handle this well.

Clean Up Unused Workflows and Automations

Automations can be sneaky. If you've got flows, triggers, or process builders firing off calls every time a record changes, they can rack up usage fast.

Audit your automation rules and remove or consolidate where possible. Less noise, fewer calls.

Use Middleware for Smart Throttling

Set up an integration layer - like MuleSoft, Boomi, or even a custom Node.js/Express app - that acts as a gatekeeper.

This middleware can:

  • Cache data
  • Throttle requests
  • Batch and schedule operations

It's like putting a smart assistant in front of Salesforce to filter and organize requests before they go through.

Set Retry Logic With Exponential Backoff

If you're making automated API calls, always build in retry logic. But don't hammer the API every second if something fails.

Instead, use exponential backoff:

const retries = 5;

for (let i = 0; i < retries; i++) {
    try {
        await callSalesforceApi();
        break;
    } catch (error) {
        await new Promise(resolve => setTimeout(resolve, Math.pow(2, i) * 1000));
    }
}

This gives Salesforce time to recover and helps you avoid throttling.

Conclusion

Salesforce API limits might seem like a frustrating bottleneck, but with the right strategy, you can dodge them like a pro. It's all about being smarter with your calls, not trying to eliminate them entirely. Monitor your usage, use the right APIs, cache where you can, and always batch when possible. Treat your API calls like money - spend wisely, and they'll never run out.

Stay proactive, and you'll keep your integrations running smoothly without ever hearing the dreaded words: You have exceeded your API limit.