DEV Community

Demo
Demo

Posted on • Originally published at orgdoc.dev

Salesforce API usage: how to monitor and optimize

APIs are the lifeblood of modern Salesforce implementations, but unchecked usage can cripple performance, spike costs, and trigger outages. I’ve seen manufacturing clients hit 50% API limit spikes during peak order processing, and healthcare orgs get slammed by EHR integrations eating 80% of their daily allotment. Here’s how to monitor and optimize—no fluff, just what works at scale.

Monitor Like a Pro: Beyond Basic Limits

Don’t just watch the 15,000 daily API call limit. Drill into usage patterns with:

  • Setup > Monitoring > API Usage: Check real-time per-user, per-app, and per-organization usage. Spot anomalies like a single integration hammering the API during off-hours.

Custom Reports: Build reports on ApiUsage and ApexApexExecution objects. Example SOQL for high-usage users:


SELECT UserId, COUNT(Id) 
FROM ApiUsage 
WHERE CreatedDate = LAST_N_DAYS:7 
GROUP BY UserId 
ORDER BY COUNT(Id) DESC

Enter fullscreen mode Exit fullscreen mode
  • Third-Party Tools: Use Salesforce's API Usage Dashboard (in Setup) or apps like API Monitor for historical trends and predictive alerts.

Optimize Ruthlessly: Industry Examples

Optimization isn’t just about cutting calls—it’s about smarter patterns. Here’s how I’ve fixed critical issues:

Manufacturing Client (200+ integrations): Their ERP sync ran 10k API calls hourly by querying all products on every sync. Solution: Use SELECT Id, Name FROM Product2 WHERE LastModifiedDate > LAST_WEEK (instead of full table scan) and batch by product family. Cut calls by 92%.

Healthcare Client (Compliance Risk): A patient portal integration hit limits due to repeated queryAll() calls for patient records. Solution: Implement for (List accs : [SELECT Id, Name FROM Account WHERE IsPatient = true]) with bulkified SOQL. Reduced calls by 70% and avoided HIPAA audit flags.

Key Optimization Tactics

Bulkify Early: Never loop inside SOQL. Always fetch data in bulk and process in memory. Example:


List accounts = [SELECT Id, Name FROM Account WHERE Status = 'Active'];
Map acctMap = new Map(accounts);
// Process map, not individual records

Enter fullscreen mode Exit fullscreen mode
  • Cache Strategically: For static data (e.g., tax rates), store in Custom Settings. Avoid repeated calls to external services. One client saved 12k calls/day by caching currency rates.

  • Use Async Wisely: Replace synchronous calls with Queueable Apex or Platform Events for non-urgent tasks. A financial client reduced real-time API calls by 40% by shifting report generation to async.

When to Panic (and When Not To)

Don’t wait for the "API Usage Exceeded" email. Set up alerts at 70% utilization (Setup > API Usage > Alert Threshold). But don’t panic over minor spikes—validate if it’s a legitimate business surge (e.g., Black Friday sales). My rule: If your org’s API usage is >30% of daily limit for 3+ consecutive days without a business driver, investigate immediately.

API optimization isn’t a one-time project—it’s continuous. Monitor daily, optimize relentlessly, and never assume a vendor’s integration is efficient. I’ve seen orgs save $50k/year in API costs just by fixing one poorly written Apex class.

Stop guessing if your API usage is hurting performance. Get a precise, actionable report of your org’s health in 60 seconds. Run your free Salesforce health scan now—it identifies API bottlenecks, bulkification gaps, and security risks before they break your business.

📚 Recommended Resource: Salesforce for Dummies — great for anyone learning Salesforce.

📚 Recommended Resource: NIST Cybersecurity Framework Guide — great for anyone security frameworks.


Need a second opinion on your Salesforce org? Request a diagnostic.

Top comments (0)