Sub topic 1
The Salesforce API landscape at a glance
Prerequisites
Assume you understand HTTP requests, JSON, REST, Salesforce records, and basic SQL-style queries. You also need a connected app configured in Salesforce and an OAuth client ID and secret.
The Salesforce API landscape
Salesforce provides APIs for different jobs. Record APIs read and change business data. Metadata and Tooling APIs manage configuration and development work. Event APIs publish changes instead of requiring repeated polling.
| API | Best fit |
|---|---|
| REST API | Everyday record access over HTTP |
| Bulk API 2.0 | Large asynchronous data loads |
| SOAP API | Older enterprise integrations with strict contracts |
| GraphQL API | Flexible reads across related data |
| Event APIs | Near-real-time notifications |
| Metadata API | Deploying configuration |
For a normal integration, start with REST API. Move to Bulk API 2.0 for high-volume processing, or to an event API when the consumer should react to changes.
Authenticating with OAuth 2.0
OAuth 2.0 lets a client obtain an access token without sending a Salesforce password with every request. The client credentials flow is suitable for server-to-server integrations when the connected app supports it.
curl -X POST "https://MyDomain.my.salesforce.com/services/oauth2/token" \
-d "grant_type=client_credentials" \
-d "client_id=$CLIENT_ID" \
-d "client_secret=$CLIENT_SECRET"Use the returned token in an Authorization: Bearer header. Store client secrets and tokens outside source code.
Querying data with SOQL and SOSL
SOQL is Salesforce Object Query Language. It retrieves fields from known objects, such as Account. SOSL is Salesforce Object Search Language. It searches text across multiple objects. Use SOQL for structured filters and relationships; use SOSL for broad text searches.
REST API: the default choice for record access
REST API resources map to Salesforce objects. A query uses /query, and a record operation uses /sobjects/ObjectName.
curl -G "https://MyDomain.my.salesforce.com/services/data/v60.0/query" \
--data-urlencode "q=SELECT Id, Name FROM Account WHERE Industry = 'Technology' LIMIT 5" \
-H "Authorization: Bearer $ACCESS_TOKEN"The same API can create, update, and delete records. Check response status codes, handle expired tokens, and respect API limits.
Exercise
Which API should you start with for a small service that reads and updates Account records synchronously?
Show answer
REST API, using SOQL for queries and sObject resources for record changes.