Salesforce top 10 API : A Complete Beginner’s Guide to Salesforce API

  • API stands for Application Programming Interface. It is a set of rules and protocols that allows different software applications to communicate with each other.
  • API is a set of rules and tools that allows different software systems to communicate with each other and interact in a structured way.
  • It acts as a bridge, enabling applications to share data and functionality efficiently.
  • Think of it as a contract or a set of instructions that specifies how software components should interact.

What is an API?

Interface: An API is like a user interface (UI) but for software programs. Just as a UI allows users to interact with software using buttons and menus, an API allows different software systems to interact with each other through defined methods and data formats.

Set of Rules: It provides a set of rules and tools for building software and interacting with other software. It specifies how to request data or services and how to format the responses.

How Does an API Work?

  • Requests and Responses: An API typically works by receiving requests from one application (the client) and sending responses back to it. For example, if you use an app to check the weather, that app might use an API to request weather data from a weather service, which then responds with the information.
  • Endpoints: APIs have endpoints, which are specific URLs where requests can be sent. Each endpoint corresponds to a different function or piece of data.
  • Methods: Common methods used in APIs include:
    • GET: Retrieve data from the server.
    • POST: Send data to the server.
    • PUT: Update existing data on the server.
    • DELETE: Remove data from the server.

Why are APIs Important?

  • Integration: APIs allow different software systems to work together, even if they are built by different developers or companies.
  • Automation: APIs enable automation by allowing software systems to communicate and perform tasks without manual intervention.
  • Extensibility: APIs let developers add new features or integrate external services into their applications easily.

Here are the list of all the API’s in salesoforce:

1. REST API:

  • Functionality: The REST API is designed for ease of use and efficiency, particularly for mobile and web applications. It allows you to interact with Salesforce objects using standard HTTP methods.
  • Features:
    • CRUD Operations: Create, Read, Update, and Delete records.
    • SOQL and SOSL Queries: Execute queries to retrieve data.
    • Metadata Operations: Access metadata and perform operations on it.
    • Custom REST Services: Define custom REST endpoints in Apex.
  • Use Cases:
    • Integrating Salesforce with web and mobile applications.
    • Performing simple CRUD operations and queries.
    • Accessing or updating Salesforce data from external systems.
Examples for Create Record:

POST /services/data/vXX.0/sobjects/Account/
Content-Type: application/json
Authorization: Bearer ACCESS_TOKEN
{
    "Name": "New Account"
}

Example for Retrieveing Record:

GET /services/data/vXX.0/sobjects/Account/{record_id} Authorization: Bearer ACCESS_TOKEN

2. SOAP API:

  • Functionality: The SOAP API is ideal for applications that require complex business logic and strong data typing. It supports synchronous operations and provides detailed error handling.
  • Features:
    • CRUD Operations: Supports operations on Salesforce records.
    • Batch Processing: Allows processing multiple records in a single request.
    • Transaction Management: Ensures data integrity and consistency.
  • Use Cases:
    • Enterprise-level integrations requiring complex transactions.
    • Applications that need strong data typing and error handling.
Create Record:<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:partner.soap.sforce.com"> <soapenv:Header/> <soapenv:Body> <urn:create> <urn:sObjects> <urn:Account> <urn:Name>New Account</urn:Name> </urn:Account> </urn:sObjects> </urn:create> </soapenv:Body> </soapenv:Envelope>

Query Records:<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:partner.soap.sforce.com"> <soapenv:Header/> <soapenv:Body> <urn:query> <urn:queryString>SELECT Id, Name FROM Account</urn:queryString> </urn:query> </soapenv:Body> </soapenv:Envelope>

3. Bulk API:

  • Functionality: The Bulk API is designed for processing large amounts of data asynchronously. It is ideal for data migration and loading tasks.
  • Features:
    • Batch Processing: Handle large volumes of data in batches.
    • Asynchronous Operations: Process data in the background without waiting for immediate results.
  • Use Cases:
    • Migrating large datasets into Salesforce.
    • Performing bulk updates or deletions.
Example to Add Batch:
POST /services/async/XX.0/job/{job_id}/batch Content-Type: text/csv Authorization: Bearer ACCESS_TOKEN Name "Account 1" "Account 2"
Example to Create Job: POST /services/async/XX.0/job Content-Type: application/json Authorization: Bearer ACCESS_TOKEN { "object": "Account", "operation": "insert", "contentType": "CSV" }

4. Streaming API:

  • Functionality: The Streaming API allows you to receive real-time notifications of changes in Salesforce data. It uses the Bayeux protocol and CometD to push updates to subscribed clients.
  • Features:
    • Real-Time Updates: Receive notifications of changes as they happen.
    • Event Channels: Subscribe to specific events or topics.
  • Use Cases:
    • Building real-time dashboards or notifications.
    • Monitoring changes to Salesforce records in real-time.
Example to Create PushTopic: POST /services/data/vXX.0/sobjects/PushTopic/ Content-Type: application/json Authorization: Bearer ACCESS_TOKEN { "Name": "AccountChanges", "Query": "SELECT Id, Name FROM Account", "ApiVersion": "XX.0" }
Example to Subscribe to PushTopic: GET /cometd/XX.0

5. Metadata API:

  • Functionality: The Metadata API allows you to manage and deploy Salesforce metadata, such as custom objects, fields, and page layouts.
  • Features:
    • Deploy and Retrieve Metadata: Move customizations between environments.
    • Manage Metadata Components: Create, update, and delete metadata components.
  • Use Cases:
    • Managing and deploying metadata configurations.
    • Automating metadata changes across different Salesforce environments.
  • Example to Retrieve Metadata:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:met="urn:metadata.tooling.soap.sforce.com"> <soapenv:Header/> <soapenv:Body> <met:retrieve> <met:retrieveRequest> <met:apiVersion>XX.0</met:apiVersion> <met:singlePackage>true</met:singlePackage> <met:unpackaged> <met:types> <met:members>*</met:members> <met:name>CustomObject</met:name> </met:types> </met:unpackaged> </met:retrieveRequest> </met:retrieve> </soapenv:Body> </soapenv:Envelope>

6. Apex REST API:

  • Functionality: The Apex REST API allows you to expose custom RESTful web services defined using Apex code.
  • Features:
    • Custom REST Endpoints: Define endpoints that handle HTTP requests and responses.
    • Custom Business Logic: Implement custom business logic in Apex.
  • Use Cases:
    • Creating custom web services to interact with Salesforce data.
    • Exposing custom business processes via REST APIs.
  • Examples: Define Apex REST Resource:
@RestResource(urlMapping='/MyResource/*') global with sharing class MyResource {           @HttpGet global static Account doGet() 
{           RestRequest req = RestContext.request; String accountId = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1); 
  return [SELECT Id, Name FROM Account WHERE Id = :accountId]; }
}

7. Apex SOAP API:

  • Functionality: The Apex SOAP API allows you to expose custom SOAP-based web services defined using Apex code.
  • Features:
    • Custom SOAP Endpoints: Define endpoints that handle SOAP requests and responses.
    • Custom Business Logic: Implement custom logic in Apex.
  • Use Cases:
    • Creating custom SOAP services to interact with Salesforce data.
    • Integrating with systems that use SOAP protocols.
  • Examples:
    • Define Apex SOAP Web Service:apexCopy code
global class MyWebService {  webservice static String helloWorld() 
 {
        return 'Hello, World!';     }
}

8. Tooling API:

  • Functionality: The Tooling API provides access to metadata and development tools, allowing you to interact with Salesforce development and debugging features.
  • Features:
    • Metadata Operations: Access and manipulate metadata components.
    • Development Tools: Access development and debugging tools.
  • Use Cases:
    • Building custom development tools and integrations.
    • Accessing and managing Salesforce metadata programmatically.
Example to retrieve metadata: GET /services/data/vXX.0/tooling/sobjects/CustomObject/ Authorization: Bearer ACCESS_TOKEN

9. Chatter REST API:

  • Functionality: The Chatter REST API allows you to interact with Chatter feeds, users, and groups within Salesforce.
  • Features:
    • Feed Management: Post updates and query feeds.
    • User and Group Management: Access and manage users and groups.
  • Use Cases:
    • Integrating Salesforce Chatter with external applications.
    • Building custom social features and dashboards.
  • Example to Post to Feed:
POST /services/data/vXX.0/chatter/feed-elements/ Content-Type: application/json Authorization: Bearer ACCESS_TOKEN { "body": { "messageSegments": [ { "type": "Text", "text": "Hello, Chatter!" } ] } }

10. Query Editor API:

  • Functionality: Allows you to execute SOQL queries programmatically to retrieve Salesforce data.
  • Features:
    • Execute SOQL Queries: Run queries to fetch data from Salesforce objects.
  • Use Cases:
    • Programmatically executing queries to fetch and process data.
    • Integrating SOQL query results into external systems.
  • Here is example to run SOQL query:
GET /services/data/vXX.0/query/?q=SELECT+Id,+Name+FROM+Account Authorization: Bearer ACCESS_TOKEN

Each API is tailored to specific needs and scenarios, so choosing the right one depends on your requirements for data handling, real-time updates, integration complexity, and more.

Having 11+ years of extensive hands-on experience in CRM application development, designing, and coding implementation of Salesforce applications on Sales Cloud, Service Cloud, and Community Cloud.

Leave a Comment