Tip of the week # 215 : Salesforce REST API

Salesforce REST API's with Examples
Description : Salesforce REST API allows external applications to interact with Salesforce using HTTP methods like GET, POST, PATCH, and DELETE. It streamlines CRUD operations, making integrations simpler and more efficient.Types of Salesforce REST API's :
-
Standard REST API : For basic record operations. (Below example for create account via REST API)
Note : You have to add all object based required field like Account has Name, Contact has Last Name etcMethod:- Post URL:- /services/data/v36.0/sobjects/Account/ Request Body :-
{ "Name" : "Account from Rest API", "phone" : "1111111111", "website" : "www.salesforce1.com", "numberOfEmployees" : "100", "industry" : "Banking" } Response Body :-
{ "id" : "00190000001pPvHAAU", "errors" : [ ], "success" : true, "created": true } -
Composite API: To execute multiple REST API requests within a single call.(Below example for create account with Contact via REST API)
Note : Its also support partial insertion with "allOrNone": true param is body.Method:- Post URL:- /services/data/v36.0/sobjects/Account/ Request Body :-
{ "compositeRequest" : [{ "method" : "POST", "url" : "/services/data/v64.0/sobjects/Account", "referenceId" : "refAccount", "body" : { "Name" : "Sample Account" } },{ "method" : "POST", "url" : "/services/data/v64.0/sobjects/Contact", "referenceId" : "refContact", "body" : { "LastName" : "Sample Contact", "AccountId" : "@{refAccount.id}" } }] } Response Body :-
{ "compositeResponse": [ { "body": { "id": "0015g00000ABCD1AAL", "success": true, "errors": [] }, "httpHeaders": {}, "httpStatusCode": 201, "referenceId": "newAccount" }, { "body": { "id": "0035g00000XYZ12AAH", "success": true, "errors": [] }, "httpHeaders": {}, "httpStatusCode": 201, "referenceId": "newContact" } ] }
Type :
Composite SObjects: Inserts multiple records of potentially different sObject types in a single request.
Composite Tree: Inserts a parent record and its related child records in a single request, maintaining the parent-child relationship. -
Bulk API:Designed for efficiently processing large data volumes in an asynchronous manner.
Method:- Post URL:- /services/data/v64.0/jobs/ingest/
CSV File Name : bulkinsert.csv (With CSV file with header as field API name of Object) File : newinsertjob.json :-
{ "object" : "Account", "contentType" : "CSV", "operation" : "insert", "lineEnding" : "LF" } Response Body :-
{ "id" : "7505fEXAMPLE4C2AAM", "operation" : "insert", "object" : "Account", "createdById" : "0055fEXAMPLEtG4AAM", "createdDate" : "2022-01-02T21:33:43.000+0000", "systemModstamp" : "2022-01-02T21:33:43.000+0000", "state" : "Open", "concurrencyMode" : "Parallel", "contentType" : "CSV", "apiVersion" : 64.0, "contentUrl" : "services/data/64.0/jobs/ingest/7505fEXAMPLE4C2AAM/batches", "lineEnding" : "LF","columnDelimiter" : "COMMA" } - Note : you can monitor the job with below REST API /services/data/v64.0/jobs/ingest/7505fEXAMPLE4C2AAM(Job Id)/successfulResults/
Happy Sharing...
Everyone has their own favorites, so please feel free to share with yours contacts and comments below for any type of help!Use below Chrome Extension for Productivity and share your feedback. Download Link : https://chromewebstore.google.com/detail/quick-shortcuts/ldodfklenhficdgllchmlcldbpeidifp?utm_source=ext_app_menu
Comments
Post a Comment