Salesforce Standard API and Custom API

AMIR SUHAIL
3 min readJun 11, 2024

--

Salesforce provides both standard APIs and custom APIs for interacting with its platform. Here’s a brief overview of each, along with examples:

Standard APIs

Salesforce standard APIs are pre-built interfaces that allow you to interact with Salesforce data and metadata. The most commonly used standard APIs are:

  1. REST API
  2. SOAP API
  3. Bulk API
  4. Streaming API

Example of REST API

The REST API is commonly used for web and mobile applications due to its simplicity and efficiency.

Example: Create an Account record using standard API.

Steps:

1- Login to your salesforce org.

2- Login to workbench.

3- Click on the utility and select Rest Explorer.

4 Add /sobjects/Account after version

5- Select the post method.

6- Enter JSON in the request body box ( I have added just name, you can add as many account fields as you want.) I am assuming there are no required fields and validations.

7-Click on execute.

An account has been created.

Custom APIs

Custom APIs in Salesforce are user-defined APIs that allow you to extend Salesforce functionality according to specific business needs. You can create custom APIs using Apex.

Example of a Custom REST API with Apex

Steps:
1- Create an Apex class with @RestResource annotation and URL mapping. Since we are creating an account, the method should be annotated with @HttpPost

@RestResource(urlMapping='/CreateAccountAPI/*')
global with sharing class CustomAPIController {

@HttpPost
global static String createAccount() {
RestRequest request = RestContext.request;
RestResponse response = RestContext.response;
Accountwrapper accountRequest = new Accountwrapper();
accountRequest = (Accountwrapper)System.JSON.deserialize(request.requestBody.toString(), Accountwrapper.class);

// Create Account
Account acc = new Account();
acc.Name = accountRequest.Name;
try {
insert acc;
return 'Account created with Id: ' + acc.Id;
} catch (DmlException e) {
return 'Error creating account: ' + e.getMessage();
}
}

//Wrapper Class to deserialize request body
global class Accountwrapper{
global String Name;
}
}

2- Login to workbench.

3- Click on the utility and select Rest Explorer.

4 Add /services/apexrest/CreateAccountAPI in the execute box

5- Select the post method.

6- Enter JSON in the request body box ( I have added just name, you can add as many account fields as you want.)

7-Click on execute.

The account has been created successfully using custom API.

Note: Standard APIs do not contain the "apexrest" keyword in the endpoint, while Custom APIs do.

Thanks for reading, follow for more interesting salesforce articles.

--

--

AMIR SUHAIL
AMIR SUHAIL

Written by AMIR SUHAIL

Tech Savvy | Writer | Code Maestro

No responses yet