Skip to main content

How to Handle Salesforce API Limits with FastAPI

About Us
Published by yuliya.dzemidchuk
27 March 2026

How to Work Around Salesforce API Limits with FastAPI

 

The Reality of Salesforce API Integrations

You’ve just been asked to connect a new customer portal, ERP system, or internal dashboard to Salesforce. It sounds straightforward on paper — Salesforce has excellent REST APIs, right?

However, in practice, challenges begin to emerge quickly.

You quickly discover that Salesforce’s native APIs are powerful… but raw, restrictive, and unforgiving in real-world enterprise scenarios.

The biggest culprit? Governor limits and the platform’s multi-tenant architecture. All enterprises have daily API request quotas that vary by edition and configuration (often in the range of tens to hundreds of thousands of calls per 24 hours, plus license-based extras). On top of that, concurrent request limits — Salesforce enforces limits such as allowing only 25 long-running calls (>20 seconds) allowed at once on PROD.

Then there’s the REST API itself. It’s synchronous and great for small, real-time operations, but it has hard caps: maximum 2,000 records per query, 6 MB payload size. Want to process 10,000 leads or sync inventory in one go? You have two options: either make hundreds of individual calls (burning through your daily quota in hours) or utilize “Bulk API 2.0”.

On top of the technical limits, you face constant data-quality battles. Salesforce returns verbose, sometimes inconsistent payloads. Field mappings break when objects change. Business rules (lead scoring, duplicate prevention, approval workflows) must be enforced somewhere — but doing it directly in every calling system leads to duplicated logic, inconsistent results, and corrupted records. Authentication tokens expire, error handling varies between endpoints, and exposing raw Salesforce credentials to frontends or external partners is a security nightmare.

The result in real projects?

  • Integrations that work in dev but collapse under moderate load.
  • Teams are spending more time fighting limits and debugging than delivering features.
  • Data inconsistencies that erode trust in the CRM.
  • Slow onboarding of new systems because every connection re-invents the wheel.
  • Production incidents when a marketing campaign or nightly sync suddenly spikes API usage.

This scenario is common across many enterprise implementations. What should be a simple data flow turns into a constant battle against the platform’s built-in safeguards — safeguards that exist for good reasons (fair resource sharing in a multi-tenant world) but make life difficult when you need reliable, scalable, and secure access to Salesforce.

This level of complexity is often unnecessary and can be avoided with the right architectural approach.

 

The Solution: Build a Smart API Layer with FastAPI

This is where FastAPI becomes a practical and effective solution. By placing a FastAPI layer between your applications and Salesforce, you regain control, improve reliability, and protect your integrations.

FastAPI is well-suited for Salesforce because it’s extremely fast, built on modern Python standards (Pydantic for validation, Starlette for performance), and excels at creating clean, documented APIs with minimal boilerplate. It lets you handle data processing, validation, and orchestration in Python before anything ever touches Salesforce.

Here’s how this architecture works in practice:

 

Middleware as the Polite Middleman

Think of middleware as the polite bouncer (or middleman) at your backend’s door. It runs on every request and can:

  • Add timing headers (X-Process-Time)
  • Handle logging
  • Enforce authentication and token refresh for Salesforce
  • Normalize responses

Your consumers receive clean, consistent, predictable data every single time — no more zoo of errors in the logs.

 

CORS and Request Handling

When different parts of your system (or frontend) talk to the API from different ports or domains, browsers and clients can block requests. Proper CORS configuration ensures everything communicates smoothly, and you can easily maintain and tune it as the project grows.

 

Smart Data Validation and Processing

Using FastAPI’s tight integration with Pydantic, you validate and transform data in Python before sending it to Salesforce. This catches invalid fields, enforces business rules, and prevents bad data from polluting your CRM.

 

How FastAPI Helps with Governor Limits

FastAPI provides practical tools to stay within Salesforce limits. These include caching for repeated queries, batching and aggregation to reduce the number of API calls, and background queues for heavy or non-urgent operations. This flexibility allows multiple strategies for optimizing API usage. Instead of letting every system fire hundreds of direct calls, you consolidate and optimize all traffic through one controlled, intelligent layer — significantly reducing the total number of calls to Salesforce.

 

Docker for Consistent Development

During normal development you’re often forced to juggle multiple CLIs. With a proper setup, you run just one command, and everything starts together in a reproducible environment:

Bash

docker compose up --build

No more “it works on my machine” drama.

 

Preparing for Production with API Gateway

When you’re ready to go live with a real hosting provider, keep in mind real security, scalability, and rate limiting. We will put an API Gateway (for example AWS API Gateway) in front of your FastAPI service. This is an extra layer of protection while your FastAPI backend stays focused on business logic.

 

Real Impact

This approach helps teams move faster, reduce bugs, improve data quality, and make Salesforce integrations much more secure and maintainable.

In practice, these patterns are typically implemented through a structured API layer — with clean middleware, proper CORS configuration, Docker-based environments, and a foundation ready for an API Gateway.


Ivan Andreyeu
Python developer
image
Expertise
Question to the expert
image

We have available resources to start working on your project within 5 business days

1 UX Designer

image

1 Admin

image

2 QA engineers

image

1 Consultant

image
Related Articles
All articles
image
How to Customize Salesforce Field Service Mobile for Your Technicians
Salesforce Field Service Mobile provides a standard technician experience that companies can extend to fit their own service processes. This article looks at areas where a custom mobile workflow can help: AI repair assistance, field documentation, external tools, back-office integrations, quotes and payments on site, barcode scanning and role-based mobile layouts. It also outlines four practical steps for planning a mobile workflow around the technician’s work.
21 October 2026
image
Salesforce Field Service Mobile: New Capabilities for Technicians
Salesforce Field Service Mobile continues to evolve with new capabilities for technicians working in the field. Explore how updates to job preparation, mobile forms, voice input, mapping, and Work Order views are changing the technician experience, and learn why configuring these capabilities around your service operations matters.
14 October 2026
image
Closing the Gap Between Field Service and Business Needs
Standard Salesforce Field Service configuration covers many service processes, but individual businesses can have different workflows, working conditions, scheduling rules, and operational requirements. This article looks at three areas where standard configuration can fall short: how technicians work, the conditions of field service operations, and business-specific processes. It also provides a practical checklist of signs that a Salesforce Field Service setup could benefit from customization.
07 October 2026