What is an API in Salesforce?
An API is an Application Programming Interface offered by Salesforce, a leading cloud-based CRM platform. The API allows developers to integrate Salesforce functionality into other applications and business systems, enabling streamlined workflows, automated processes, and greater productivity.
In essence, the API is a messenger that pulls information from one place and feeds it to another. APIs are everywhere and have many different faces and capabilities. For example, when your car’s navigation system uses Google Maps to direct you to the airport, that’s an API. Google allows navigation systems to use its popular mapping software — for a price (more on that later). Likewise, if there are share buttons at the bottom of your company’s blog posts, those are also APIs. Each one allows users to easily share content with their Facebook friends, Twitter followers, or Instagram feed.
API stands for Application Programming Interface and it’s simply another way of sending commands to Salesforce, only this time there’s no graphical UI to work through, instead developers use the APIs to send commands like View or Save to Salesforce programmatically by writing platform code.
Salesforce provides a handy tool for determining which API to use in different situations.
API NAME | API TYPE | DATA FORMAT | COMMUNICATION |
---|---|---|---|
REST API | REST | JSON, XML | Synchronous |
SOAP API | SOAP (WSDL) | XML | Synchronous |
Connect REST API | REST | JSON, XML | Synchronous (photos are processed asynchronously) |
Apex REST API | REST | JSON, XML, Custom | Synchronous |
Apex SOAP API | SOAP (WSDL) | XML | Synchronous |
Analytics REST API | REST | JSON, XML | Synchronous |
User Interface API | REST | JSON | Synchronous |
GraphQL API | GraphQL | JSON | Synchronous |
Tooling API | REST or SOAP (WSDL) | JSON, XML, Custom | Synchronous |
Bulk API 2.0 | REST | CSV | Asynchronous |
Metadata API | SOAP (WSDL) | XML | Asynchronous |
Pub/Sub API | gRPC and protocol buffers | Binary | Asynchronous |
When to Use REST API
REST API provides a powerful, convenient, and simple REST-based web services interface for interacting with Salesforce. Its advantages include ease of integration and development, and it’s an excellent choice of technology for use with mobile applications and web projects. For certain projects, you can use REST API with other Salesforce REST APIs. To build UI for creating, reading, updating, and deleting records, including building UI for list views, actions, and dependent picklists, use User Interface API. To build UI for B2B Commerce on Lightning, CMS managed content, Experience Cloud sites, or Chatter, use Connect REST API. If you have many records to process, consider using Bulk API, which is based on REST principles and optimized for large sets of data.
When to Use SOAP API
SOAP API provides a powerful, convenient, and simple SOAP-based web services interface for interacting with Salesforce. You can use SOAP API to create, retrieve, update, or delete records. You can also use SOAP API to perform searches and much more. Use SOAP API in any language that supports web services.
For example, you can use SOAP API to integrate Salesforce with your org’s ERP and finance systems. You can also deliver real-time sales and support information to company portals and populate critical business systems with customer information.
When to Use Connect REST API
Connect REST API provides programmatic access to B2B Commerce for Lightning, CMS managed content, Experience Cloud sites, files, notifications, topics, and more. Use Connect REST API to display Chatter feeds, users, and groups, especially in mobile applications.
See Connect REST API Developer Guide.
When to Use Apex REST API
Use Apex REST API when you want to expose your Apex classes and methods so that external applications can access your code through REST architecture. Apex REST API supports both OAuth 2.0 and Session ID for authorization.
See Apex Developer Guide: Exposing Apex Classes as REST Web Services.
When to Use Apex SOAP API
Use Apex SOAP API when you want to expose Apex methods as SOAP web service APIs so that external applications can access your code through SOAP.
Apex SOAP API supports both OAuth 2.0 and Session ID for authorization.
See Apex Developer Guide: Exposing Apex Methods as SOAP Web Services and SOAP API Developer Guide: Apex-Related Calls.
When to Use Analytics REST API
You can access CRM Analytics assets such as datasets, lenses, and dashboards programmatically using the Analytics REST API. Send queries and access datasets that have been imported into the analytics platform. Create and retrieve lenses. Access XMD information. Retrieve a list of dataset versions. Create and retrieve CRM Analytics apps. Create, update, and retrieve dashboards. Retrieve a list of dependencies for an application. Determine what features are available to the user. Work with snapshots. Manipulate replicated datasets.
See Analytics REST API Developer Guide.
When to Use User Interface API
Build Salesforce UI for native mobile apps and custom web apps using the same API that Salesforce uses to build Lightning Experience and Salesforce for Android, iOS, and mobile web. Build user interfaces that let users work with records, list views, actions, favorites, and more. Not only do you get data and metadata in a single response, but the response matches metadata changes made to the org by Salesforce admins. You don’t worry about layouts, picklists, field-level security, or sharing—all you do is build an app that users love.
See User Interface API Developer Guide.
When to Use GraphQL API
Build highly responsive and scalable apps by returning only the data a client needs, all in a single request. GraphQL API overcomes the challenges posed by traditional REST APIs through field selection, resource aggregation, and schema introspection. Field selection reduces the size of the payload, sending back only fields that were included in the query. Aggregations reduce round trips between the client and server, returning a set of related resources within a single response. Schema introspection enables a user to see the types, fields, and objects that the user has access to.
See GraphQL API Developer Guide.
When to Use Tooling API
Use Tooling API to integrate Salesforce metadata with other systems. Metadata types are exposed as sObjects, so you can access one component of a complex type. This field-level access speeds up operations on complex metadata types. You can also build custom development tools for Force.com applications. For example, use Tooling API to manage and deploy working copies of Apex classes and triggers and Visualforce pages and components. You can also set checkpoints or heap dump markers, execute anonymous Apex, and access logging and code coverage information.
REST and SOAP are both supported.
See Tooling API.
When to Use Bulk API 2.0
Use Bulk API 2.0 to query, queryAll, insert, update, upsert, or delete a large number of records asynchronously. Bulk API 2.0 is designed on the Salesforce REST framework.
Any data operation that includes more than 2,000 records is a good candidate for Bulk API 2.0 to successfully prepare, execute, and manage an asynchronous workflow that uses the Bulk framework. It’s best if jobs with fewer than 2,000 records involve “bulkified” synchronous calls in REST (for example, Composite) or SOAP.
When working with large volumes of data, it’s the easiest way to create, read, update, and delete (CRUD) records at scale. If your job includes just one sObject type or extracts up to 1 TB of data per day, Bulk API 2.0 is your Salesforce API of choice.
See Bulk API 2.0 and Bulk API Developer Guide.
When to Use Metadata API
Use Metadata API to retrieve, deploy, create, update, or delete customizations for your org. The most common use is to migrate changes from a sandbox or testing org to your production environment. Metadata API is intended for managing customizations and for building tools that can manage the metadata model, not the data itself.
The easiest way to access the functionality in Metadata API is to use the Salesforce Extensions for Visual Studio Code or Salesforce CLI. Both tools are built on top of Metadata API and use the standard tools to simplify working with Metadata API.
- The Salesforce Extensions for Visual Studio Code includes tools for developing on the Salesforce platform in the lightweight, extensible VS Code editor. These tools provide features for working with development orgs (scratch orgs, sandboxes, and DE orgs), Apex, Aura components, and Visualforce.
- Salesforce CLI is ideal if you use scripting or the command line for moving metadata between a local directory and a Salesforce org.
See Metadata API Developer Guide.
When to Use Pub/Sub API
You can use Pub Sub API to integrate external systems with events. Event streams are based on custom payloads through platform events or changes in Salesforce records through Change Data Capture. In Salesforce, you can publish and subscribe to events with Apex triggers, Process Builder, and Flow Builder.
Pub/Sub API is built for high scale, bi-directional event integration with Salesforce. Use Pub/Sub API to efficiently publish and subscribe to binary event messages in the Apache Avro format. Pub/Sub API is based on gRPC and HTTP/2 and uses a pull-based model so that you can control the subscription flow. With Pub/Sub API, you can use one of the 11 programming languages that gRPC supports.
Use the type of streaming event that suits your needs.
- Change Data Capture Event: Receive changes to Salesforce records with all changed fields. Change Data Capture supports more standard objects than PushTopic events and provides more features, such as header fields that contain information about the change.
- Platform Event: Publish and receive custom payloads with a predefined schema. The data can be anything you define, including business data, such as order information. Specify the data to send by defining a platform event. Subscribe to a platform event channel to receive notifications.
- Legacy Events: PushTopic and Generic Event: PushTopic and generic events are first-generation events. They have limited support and are no longer updated with new features. We recommend that you use Change Data Capture events instead of PushTopic events and Platform Events instead of Generic events.