๐ Using Salesforce REST API: A Beginnerโs Guide
The Salesforce REST API allows you to access and manipulate Salesforce data programmatically using standard HTTP methods. Itโs lightweight, easy to use, and ideal for integrating Salesforce with external applications, web apps, or custom tools.
๐ What is the Salesforce REST API?
The REST API (Representational State Transfer) provides a simple, JSON-based interface to interact with Salesforce objects and data.
You can:
- Retrieve data from Salesforce
- Create, update, and delete records
- Run SOQL queries
- Perform searches and analytics
๐ Prerequisites
Before using the REST API, you need:
- Salesforce Edition with API access (Enterprise, Developer, Performance, Unlimited)
- A Connected App set up in Salesforce for authentication
- API-enabled user profile
- A REST API tool like Postman or
cURL
๐งฐ Step 1: Create a Connected App
- Go to Setup โ App Manager
- Click New Connected App
- Fill in:
- Name
- Contact Email
- Under API (Enable OAuth Settings):
- Check Enable OAuth Settings
- Set a Callback URL (e.g.,
https://login.salesforce.com/services/oauth2/success
) - Select scopes like:
Access and manage your data (api)
Perform requests on your behalf at any time (refresh_token)
- Save and note your Consumer Key and Consumer Secret
๐ Step 2: Authenticate (OAuth 2.0 Flow)
Send a POST request to:
https://login.salesforce.com/services/oauth2/token
With the following parameters:
grant_type
= password
client_id = YOUR_CONSUMER_KEY
client_secret = YOUR_CONSUMER_SECRET
username = YOUR_USERNAME
password = YOUR_PASSWORD+SECURITY_TOKEN
๐ Note: Never share your credentials or tokens in public.
A successful response returns an access token and instance URL.
๐ Step 3: Make API Calls
๐ Example 1: Retrieve a Record (GET)
GET /services/data/v59.0/sobjects/Account/001XXXXXXXXXXXX
Host: yourInstance.salesforce.com
Authorization: Bearer YOUR_ACCESS_TOKEN
๐ Example 2: Create a Record (POST)
POST /services/data/v59.0/sobjects/Contact/
Host: yourInstance.salesforce.com
Authorization: Bearer YOUR_ACCESS_TOKEN
Content-Type: application/json
{
"FirstName": "John",
"LastName": "Doe",
"Email": "john.doe@example.com"
}
๐ Example 3: Run SOQL Query
GET /services/data/v59.0/query/?q=SELECT+Name,+Industry+FROM+Account
Host: yourInstance.salesforce.com
Authorization: Bearer YOUR_ACCESS_TOKEN
๐ก Tips for Beginners
Use Postman to test endpoints and explore request/response formats.
Refer to the Salesforce Object Reference for field names and API names.
Always check API version compatibility (e.g., /v59.0/).
Handle rate limits and token expiration gracefully.
Use refresh tokens for long-term access without logging in each time.
๐ FAQs
Q: Can I use the REST API in Salesforce Essentials?
A: No, API access is not available in Salesforce Essentials.
Q: Do I need coding experience to use the REST API?
A: Basic familiarity with HTTP and JSON is helpful. Tools like Postman reduce the need for coding.
Q: Whatโs the difference between REST and SOAP in Salesforce?
A: REST is lighter, uses JSON, and is easier for web-based apps. SOAP is XML-based and suited for enterprise systems.