Sub topic 1
The Salesforce API landscape at a glance
Salesforce exposes many APIs, and each one exists because a different kind of client needs a different trade-off. This chapter gives you a map. It names each API, says what it is for, and shows the few questions that separate one from another. Later chapters cover authentication, queries, and each API in detail.
Prerequisites
This chapter assumes you have the following:
- A working knowledge of HTTP: methods, status codes, headers, and request and response bodies.
- Comfort reading JSON and simple Apex or JavaScript.
- Familiarity with Salesforce objects, fields, and records, such as Account and Contact.
- Basic SQL-style querying. You do not need SOQL yet.
You do not need a Salesforce org to read this chapter. You will need one for the later chapters that run requests.
Why there are so many APIs
A single API cannot serve every integration well. Think of four different clients:
- A mobile app that reads one customer record and needs a fast answer.
- A nightly job that loads two million rows.
- A billing system that must learn about a closed deal within seconds.
- A deployment tool that moves a custom field from a sandbox to production.
The first wants low latency per call. The second wants throughput and does not care about latency. The third wants to be told about changes rather than ask for them. The fourth does not touch records at all. It changes the structure that holds the records.
Salesforce built a separate API for each of these needs. The names look confusing at first, but the underlying choices are few.
Four questions that sort the APIs
Most APIs fall into place once you answer four questions about your requirement.
- What kind of thing are you touching? Data is records and their values. Metadata is the definition of objects, fields, flows, and Apex code. Data APIs and metadata APIs are separate families.
- How much, and how fast? A handful of records per call suits a synchronous API. Millions of records suit an asynchronous API that you submit to and poll.
- Who starts the conversation? In request/response, your client asks. In publish/subscribe, Salesforce pushes events to you.
- Whose logic runs? Standard APIs apply Salesforce's built-in behavior. A custom endpoint runs your own Apex.
The protocol (REST with JSON, SOAP with XML, gRPC, or CSV over HTTP) is a fifth, weaker question. It usually follows from the first four, or from what your platform's tooling supports.
The map
The APIs in one pass
Request/response data APIs
REST API is the general-purpose option. It uses standard HTTP methods and JSON (XML is also supported) to create, read, update, and delete records. It also runs SOQL queries and describes objects. If you have no special requirement, start here. Its extensions, the Composite and Batch resources, combine several operations into one HTTP call.
SOAP API offers similar data operations through a WSDL contract (an XML file describing the service). Tools in Java and .NET can generate strongly typed client code from the WSDL. It remains common in older integrations and in enterprise middleware built around WSDL.
GraphQL API lets a client name exactly the fields and related records it wants, in one request. That avoids the over-fetching and multiple round trips that REST sometimes needs for related data. It suits read-heavy clients that assemble screens from several objects.
UI API returns record data together with the metadata needed to draw a screen, such as layouts, picklist values, and field labels. It respects the user's field-level security, so it suits custom user interfaces. Lightning Web Components use it through built-in wire adapters. Connect REST API covers Salesforce features outside the plain record model, such as Chatter feeds, communities, and files.
Bulk and asynchronous data
Bulk API 2.0 is for large volumes. You create a job, upload a CSV, and tell Salesforce the upload is complete. Salesforce then processes it asynchronously, and you poll for the result. It trades latency for throughput, so a single job can load or query millions of records without per-record round trips.
Event-driven data
Platform Events are custom messages you define. Salesforce or an external system publishes them, and subscribers receive them. Change Data Capture (CDC) publishes a message automatically when records are created, updated, deleted, or undeleted, so external systems can stay in sync without polling. Pub/Sub API is the gRPC-based interface for subscribing to and publishing these events. It is the current recommended way for external clients to consume them. The older Streaming API, built on CometD, still exists, but you should choose Pub/Sub API for new work.
Custom logic
Apex REST (and Apex SOAP) lets you expose your own Apex class as an endpoint under /services/apexrest/. Use it when an integration needs server-side logic that no standard resource provides, such as applying several business rules in one transaction.
Metadata and development
Metadata API retrieves and deploys the definition of an org: custom objects, fields, page layouts, Apex classes, and so on. Deployment tools and CI pipelines use it. Tooling API gives finer-grained access for development tools, such as querying Apex classes, running anonymous Apex, or reading debug logs. Neither one moves business records.
Salesforce has other APIs too, such as the Analytics REST API for reports and dashboards. They fit the same sorting questions, and this tutorial focuses on the ones above.
A quick comparison
| API | Works on | Style | Typical use |
|---|---|---|---|
| REST API | Records | Synchronous, JSON | General integrations, small to medium volumes |
| SOAP API | Records | Synchronous, XML with WSDL | Legacy and WSDL-driven tools |
| GraphQL API | Records (mainly reads) | Synchronous, single endpoint | Flexible reads across related objects |
| UI API | Records plus layout metadata | Synchronous, JSON | Custom user interfaces |
| Bulk API 2.0 | Records | Asynchronous, CSV | Loads and extracts of large volumes |
| Pub/Sub API | Events | Streaming, gRPC | Reacting to changes in near real time |
| Apex REST | Anything your Apex touches | Synchronous, custom | Server-side logic behind one call |
| Metadata API | Org configuration | Deploy and retrieve | Moving configuration between orgs |
| Tooling API | Development artifacts | Synchronous | IDEs and developer tools |
What all of them share
Every API in the table sits behind the same authentication model. Clients obtain an OAuth 2.0 access token and send it with each request. All of them also count toward org-level limits, which the later chapter on limits covers. Two practical points apply everywhere:
- The user or integration identity needs the API Enabled permission. Without it, calls fail even with a valid token.
- Your org's edition must include API access. Some editions, such as Professional, need an add-on.
Versioned REST-style endpoints include the API version in the path. You can ask any org which versions it supports. This call needs no token:
curl "https://MyDomain.my.salesforce.com/services/data/"The response is a JSON array of objects with label, url, and version fields, one per supported version. Pick a version deliberately and keep it in configuration, so an upgrade is a conscious change.
Common mistakes
- Using REST for a bulk load. Looping over a million rows with one call each burns your daily request allocation and takes hours. Bulk API 2.0 is the right tool.
- Using Bulk API 2.0 for a single record. Job setup, upload, and polling add overhead. A synchronous call is simpler and faster.
- Polling for changes. A client that queries every minute for "records modified since" wastes calls and still lags. CDC delivers the change itself.
- Confusing Metadata API and Tooling API. Metadata API deploys whole configuration sets. Tooling API serves interactive tooling and queries about development artifacts. Neither one reads or writes ordinary Account or Contact rows.
- Building custom Apex endpoints too early. If a standard resource, or a Composite request, does the job, you avoid maintaining and testing your own code.
- Hard-coding the instance URL. Use your My Domain URL, and use the instance URL returned during authentication. Instances can change.
Exercises
Exercise
A partner system must learn within seconds whenever an Opportunity is closed, without repeatedly querying Salesforce. Which family of APIs fits, and which specific feature publishes the changes automatically?
Show answer
The event-driven family fits. Change Data Capture publishes a message for each record change, and the partner can subscribe to those messages through Pub/Sub API instead of polling.
Exercise
A team wants to move a new custom field and its page layout from a sandbox to production. Should they use REST API, Bulk API 2.0, or Metadata API, and why?
Show answer
Metadata API. The field and layout are configuration, not records. REST API and Bulk API 2.0 read and write record data, while Metadata API retrieves and deploys the definitions of objects, fields, and layouts.
Exercise
Name two reasons you might choose REST API over Bulk API 2.0 for an integration.
Show answer
Any two of these: the integration handles one record or a small number of records per call. It needs an immediate response rather than polling for a job result. It needs a feature of the synchronous API, such as describing an object or running a short SOQL query. The setup is simpler, since there is no job lifecycle to manage.