Salesforce provides powerful APIs to allow developers to connect external applications with the Salesforce platform. The REST API is one of the most common types of APIs being used. Through standard HTTP methods (GET, POST, PATCH, and DELETE), developers can use the Salesforce REST API to interact with Salesforce data. Simple, enable easy integration of a web or mobile application to Salesforce.
In this blog, we’ll discuss what the Salesforce REST API is, its usage, and how beginners can start using it step by step.
What is Salesforce REST API?
Using RESTful web services, external applications have the ability to communicate with Salesforce via the Salesforce REST API. Representational State Transfer, more commonly known as REST, is an architectural design style often used to create web services.
With the REST API, developers can manage the following operations:
Retrieving Salesforce records
Creating new records
Updating existing records
Deleting records
Running SOQL queries
Accessing metadata
You can perform all these operations just using simple HTTP requests.
Why use Salesforce REST API?
Below are the justifications why developers choose to use Salesforce REST API.
1. Easy Integration
It adopts the REST API architecture style using standard HTTP methods along with JSON format, which means it is easy to use across various programming languages like JavaScript, Python, Java, and PHP.
2. Lightweight
REST APIs usually respond in JSON format, which is light and easy to parse.
3. Mobile and Web Friendly
The REST API is commonly used in mobile apps and web applications, as well as single-page apps like Lightning Web Components.
4. Fast Development
Integrating new technologies can be faster without extensive configurations from developers.
Salesforce REST API prerequisites
There are some prerequisites for using Salesforce REST API, like:
A Salesforce account
API access enabled
Connected App configuration
Access token and instance URL
After this is available, you can start making API requests.
Step 1: Create a Connected App in Salesforce
A Connected App allows external applications to securely connect to Salesforce.
Follow these steps:
- Go to Setup
- Search for App Manager
- Click New Connected App
- Enter the following details:
- Connected App Name
- API Name
- Contact Email
- Enable OAuth Settings
- Enter a Callback URL
- Add OAuth Scopes such as:
- Full Access
- Access and manage your data (api)
After saving the connected app, Salesforce will generate a Consumer Key and Consumer Secret. These credentials are used for authentication.
Step 2: Authenticate Using OAuth
Salesforce REST API requires authentication using OAuth. OAuth allows secure access without exposing user credentials.
To authenticate, send a POST request to the Salesforce token endpoint.
Example request:
POST https://login.salesforce.com/services/oauth2/token
Required parameters include:
- grant_type=password
- client_id=Consumer Key
- client_secret=Consumer Secret
- username=Salesforce Username
- password=Password + Security Token
After a successful request, Salesforce returns a response containing:
- access_token
- instance_url
- token_type
The access token is required for all API requests.
Step 3: Make Your First REST API Request
Once you receive the access token, you can start making API requests.
Example: Retrieve Account records.
HTTP Request:
GET /services/data/v58.0/sobjects/Account
Headers:
Authorization: Bearer access_token
Example URL:
https://yourInstance.salesforce.com/services/data/v58.0/sobjects/Account
The response will return Account data in JSON format.
Step 4: Create a Record Using REST API
To create a new record, use the HTTP POST method.
Example: Create an Account.
Endpoint:
/services/data/v58.0/sobjects/Account
Request Body (JSON):
{
"Name": "ABC Technologies",
"Industry": "IT"
}
Salesforce will return the new record ID if the request is successful.
Step 5: Update a Record
To update a record, use the PATCH method.
Endpoint:
/services/data/v58.0/sobjects/Account/{RecordId}
Example Request Body:
{
"Industry": "Software"
}
This will update the Industry field for the specified record.
Step 6: Delete a Record
To delete a record, use the DELETE method.
Endpoint:
/services/data/v58.0/sobjects/Account/{RecordId}
If the request is successful, Salesforce will delete the record and return a success response.
Step 7: Run SOQL Queries Using REST API
Salesforce REST API also allows developers to run SOQL queries.
Example:
GET /services/data/v58.0/query/?q=SELECT+Id,Name+FROM+Account
This query retrieves Account record IDs and Names.
The response will contain:
- totalSize
- done
- records
This makes it easy to retrieve specific data from Salesforce.
What are the Common HTTP Methods in Salesforce REST API?
Method | Purpose
GET | Retrieve data
POST | Create records
PATCH | Update records
DELETE | Delete records
These methods are consistent with standard REST practices.
Salesforce REST API Testing Tools
Newbies use tools to test their REST API requests easily.
Some popular tools include:
Postman
Workbench
cURL
REST Explorer in Salesforce
Postman because it is a simple interface for sending HTTP requests and looking at responses.
Salesforce REST API: Best practices when using
These best practices will help make sure you are using the API efficiently:
1. Use Proper Authentication
Use OAuth authentication at all times rather than storing user credentials.
2. Handle Errors Properly
Making sure response codes are received and reacting to error conditions in your application.
3. Respect API Limits
Salesforce has a daily limit for APIs, no unnecessary API calls.
4. Use Bulk APIs for Large Data
● Salesforce Bulk API — For large data operations, if you need more than the governor limits for the REST API.
5. Secure Access Tokens
Public code repositories should never leak access tokens.
In this blog post, we will cover everything you need to know about the Salesforce REST API. CRUD operation in REST APIs is based on simple HTTP requests that allow developers to easily create, read, update, and delete Salesforce records.
Just for starters, this will be needed to create a Connected App, use OAuth for authentication, and send REST API requests. Tools such as Postman allow us to easily and effectively test these requests.
Do visit our channel to know more: SevenMentor
Author:-
Komal Wavare
Komal Wavare
Expert trainer and consultant at SevenMentor with years of industry experience. Passionate about sharing knowledge and empowering the next generation of tech leaders.