0% found this document useful (0 votes)
18 views9 pages

Et

A REST API (Representational State Transfer) is a lightweight, stateless communication protocol used for integrating with Salesforce, supporting standard HTTP methods for data interaction. Salesforce offers various REST APIs, including SObject, Query, Search, and Bulk APIs, each designed for specific operations such as CRUD actions, data retrieval, and handling large data volumes. Best practices for using REST APIs include secure authentication, error handling, and optimizing queries to ensure efficient integration with external systems.

Uploaded by

gkrmtech
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views9 pages

Et

A REST API (Representational State Transfer) is a lightweight, stateless communication protocol used for integrating with Salesforce, supporting standard HTTP methods for data interaction. Salesforce offers various REST APIs, including SObject, Query, Search, and Bulk APIs, each designed for specific operations such as CRUD actions, data retrieval, and handling large data volumes. Best practices for using REST APIs include secure authentication, error handling, and optimizing queries to ensure efficient integration with external systems.

Uploaded by

gkrmtech
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

What is a REST API?

• REST (Representational State Transfer): A lightweight, stateless communication protocol widely


used for integrations.
• Supports standard HTTP methods like GET, POST, PUT, PATCH and DELETE to interact with
Salesforce data.
• Supports two primary operations:
o Inbound REST API: External systems call Salesforce APIs.
o Outbound REST API: Salesforce calls external APIs using Apex code.

Types of REST APIs in Salesforce:


1. SObject REST API
• Purpose: Perform CRUD (Create, Read, Update, Delete) operations on Salesforce standard
and custom objects.
• Key Features:
o Access object records directly.
o Includes DML operations and metadata for objects.
• Example Endpoint:
o Retrieve an Account record:
/services/data/v58.0/sobjects/Account/{AccountId}
• Use Case:
o Update a contact's details in real time from an external system.

2. Query REST API (SOQL)


• Purpose: Retrieve records using Salesforce Object Query Language (SOQL).
• Key Features:
o Supports complex queries, filtering, and relationships.
o Returns data in JSON format.
• Example Endpoint:
/services/data/v58.0/query?q=SELECT+Name,Industry+FROM+Account+WHERE+Industry='Fi
nance'
• Use Case:
o Fetching customer data for a reporting dashboard
3. Search REST API (SOSL)
• Purpose: Perform full-text searches across multiple objects.
• Key Features:
o Supports global searches for keywords.
o Faster for retrieving records based on text matches.
• Example Endpoint:
/services/data/v58.0/search?q=Acme
• Use Case:
o Finding records (e.g., Accounts, Contacts) that match a user-entered keyword.

4. Chatter REST API


• Purpose: Access and manage Salesforce Chatter features.
• Key Features:
o Post feeds, comments, and manage groups.
o Retrieve Chatter updates and notifications.
• Example Endpoint:
/services/data/v58.0/chatter/feeds
• Use Case:
o Integrate Chatter notifications into an employee portal.

5. Tooling API
• Purpose: Interact with Salesforce metadata programmatically.
• Key Features:
o Access metadata like Apex classes, triggers, and Visualforce pages.
o Perform operations like retrieving or deploying code.
• Example Endpoint:
/services/data/v58.0/tooling/sobjects/ApexClass
• Use Case:
o Building a CI/CD pipeline to deploy Apex code.
6. Composite REST API
• Purpose: Combine multiple requests into a single API call.
• Key Features:
o Reduces API call limits.
o Supports batch processing and dependencies between operations.
• Example Endpoint:
/services/data/v58.0/composite
• Use Case:
o Creating an Account and its related Contacts in a single API request.

7. Batch REST API


• Purpose: Execute multiple REST API requests in a single batch.
• Key Features:
o Supports parallel processing of unrelated operations.
• Example Endpoint:
/services/data/v58.0/composite/batch
• Use Case:
o Performing bulk updates on multiple records.

8. Analytics REST API


• Purpose: Access Salesforce reports, dashboards, and datasets.
• Key Features:
o Query and manage analytics data.
o Retrieve dashboard metadata and visualizations.
• Example Endpoint:
/services/data/v58.0/analytics/reports/{reportId}
• Use Case:
o Fetching report data for external business intelligence tools.
9. Connect REST API
• Purpose: Integrate Salesforce with external social platforms and apps.
• Key Features:
o Access Salesforce data in external apps.
o Includes capabilities for feeds, users, and resources.
• Example Endpoint:
/services/data/v58.0/connect/organization
• Use Case:
o Embedding Salesforce data into a custom web portal.

10. Bulk REST API


• Purpose: Handle large-volume data operations asynchronously.
• Key Features:
o Supports up to 15 million records per job.
o Ideal for data migrations and ETL processes.
• Example Endpoint:
/services/data/v58.0/jobs/ingest
• Use Case:
o Migrating legacy CRM data into Salesforce.

How to Use Standard REST APIs:


• Authentication:
o Use OAuth 2.0 to get an access token.
o Example cURL command:
curl -X POST -H "Authorization: Bearer <Access_Token>" \

https://yourInstance.salesforce.com/services/data/v58.0/sobjects/Account

• Common code for any REST Callout:


• Testing with Postman:
o Set up a connected app in Salesforce for OAuth.
o Authenticate and get a token.
o Use the token to test REST API endpoints in Postman.
Use Case for Standard APIs:
• Fetching a list of accounts for a customer dashboard.
• Creating leads from an external marketing system.

11. Custom REST APIs in Salesforce


Why Create Custom APIs?
• To expose business logic tailored to specific requirements.
• Example: A custom API to calculate loan eligibility based on inputs.
How to Implement Custom REST APIs:
a) Create an Apex Class with @RestResource Annotation:

• Example:

@RestResource(urlMapping='/LoanEligibility/*')

global class LoanEligibilityAPI {

@HttpPost

global static String checkEligibility(String customerId, Decimal income) {

// Business logic here

return 'Eligible';

b) HTTP Methods in Custom APIs:


o @HttpGet: For retrieving data.
o @HttpPost: For creating or processing data.
o @HttpPut: For updating data.
o @HttpPatch: For upserting data.
o @HttpDelete: For deleting records.
c) Expose Business Logic:
o Add business logic in Apex to process API inputs.
Testing Custom APIs:
• Use Postman or tools like cURL:
curl -X POST -H "Authorization: Bearer <Access_Token>" \

-H "Content-Type: application/json" \

-d '{"customerId":"12345","income":75000}' \

https://yourInstance.salesforce.com/services/apexrest/LoanEligibility/

Use Case for Custom APIs:


• A fintech company exposing a custom API to calculate interest rates based on loan types.

Inbound and Outbound REST API Scenarios in Salesforce:


1. Inbound REST API (External → Salesforce)
Purpose: Allow external systems to push data or fetch data from Salesforce.
• Use Case:
o A payment gateway like Stripe sends transaction details to Salesforce.
o A marketing tool fetches lead data from Salesforce for email campaigns.
• How It Works:
o External systems authenticate via OAuth 2.0 or a session ID.
o Salesforce provides standard or custom endpoints to receive requests.
• Example Scenario:
o Custom REST API: Expose a custom endpoint to receive data:
@RestResource(urlMapping='/PaymentAPI/*')

global class PaymentAPI {

@HttpPost

global static void receiveTransaction() {

RestRequest req = RestContext.request;

String transactionDetails = req.requestBody.toString();

// Process and store the transaction

}
• Testing:
o Use Postman or cURL to simulate requests.

2. Outbound REST API (Salesforce → External)


Purpose: Allow Salesforce to interact with external systems.
• Use Case:
o Salesforce sends order details to an ERP system like SAP.
o Salesforce fetches weather data from an external API to display in a dashboard.
• How It Works:
o Create Named Credentials for secure external API calls.
o Write Apex code to send requests and process responses.
• Example Scenario:
o Calling External Weather API:
public class WeatherService {

public static void getWeather(String city) {

HTTP http = new HTTP();

HttpRequest req = new HttpRequest();

req.setEndpoint('https://abc.com/animals’);

req.setMethod('GET');

req.setHeader(‘Content-Type’, ‘application/json;charset=UTF-8’);

req.setBody(‘{“name”:”Elon Musk”}’);

HttpResponse res = http.send(req);

System.debug('Response: ' + res.getBody());

• Testing:
o Use Salesforce Developer Console to invoke the Apex method.
Real-World Use Cases
Inbound REST API Examples
1. Customer Feedback Submission:
o An external form captures feedback and sends it to Salesforce for storage under a
custom object.
2. Third-Party E-Commerce Platform Sync:
o Shopify sends order details to Salesforce for fulfillment tracking.
Outbound REST API Examples
1. Send Notifications to Messaging Apps:
o Salesforce sends lead updates to Slack or Microsoft Teams.
2. Sync Data with ERP System:
o Salesforce sends invoices to an ERP system for processing.

Steps to Configure and Test REST API Use Cases


For Inbound APIs:
1. Enable API Access in Salesforce:
o Go to Setup → Profiles → Enable "API Enabled" permission.
2. Create Custom REST API in Apex (if needed):
o Use @RestResource and HTTP methods (@HttpGet, @HttpPost).
3. Authentication:
o Use OAuth 2.0 for secure access by external systems.
4. Test Using Postman:
o Send test requests to your custom or standard REST API endpoints.
For Outbound APIs:
1. Configure Named Credentials:
o Navigate to Setup → Named Credentials → Create a new credential.
2. Write Apex Code to Send HTTP Requests:
o Use the HttpRequest and HttpResponse classes in your code.
3. Testing:
o Test in the Developer Console or a test class.
4. Handle Errors:
o Include error handling for failed responses (e.g., HTTP 404, 500).

Best Practices for REST APIs


1. Authentication: Use OAuth 2.0 for secure access.
2. Error Handling: Return meaningful error messages with proper HTTP status codes.
3. Optimize Queries: Fetch only required fields to minimize payload size.
4. Limit API Calls: Use Composite or Batch API to stay within limits.
5. Secure Access: Use profiles and permission sets to restrict API usage.
6. Monitor Limits: Respect Salesforce's API usage limits to avoid disruptions.
7. Use Named Credentials: Simplify external callouts and maintain security.

Advantages of Using REST APIs in Salesforce


1. Easy integration with external systems using standard HTTP methods.
2. Lightweight and stateless, making it ideal for modern web and mobile apps.
3. Enables real-time data synchronization.
4. Allows integration with multiple systems.
5. Supports both JSON and XML (JSON preferred / XML optional).
6. Works with a variety of external platforms like ERP, CRM, and IoT devices.

Use Cases for REST API Implementation


1. Real-Time Data Sync: Sync customer information from Salesforce to an external CRM.
2. Mobile App Integration: A custom API to fetch Salesforce data for a mobile app.
3. Third-Party Tool Integration: Using REST APIs to send Salesforce leads to marketing platforms
like Mailchimp or HubSpot.

Pro Tip: Always follow Salesforce API limits to ensure smooth functioning of your integrations. For large-
scale integrations, consider using Bulk API or Streaming API.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy