In this blog we will learn how to insert, update or delete a record by Rest API without any code.
1) Create a record
Method :- Post
URL:- /services/data/v36.0/sobjects/Account/
Request Body :-
1 | {"Name" : "Account from Rest API", "phone" : "1111111111", "website" : "www.salesforce1.com", "numberOfEmployees" : "100", "industry" : "Banking" } |
|
Response
1 | {
"id" : "0019000001hE8apAAC",
"success" : true,
"errors" : [ ]
} |
2) Update a record
Method :- Patch
URL:- /services/data/v36.0/sobjects/Account/0019000001hE8apAAC
Request Body :-
1 | {"Name" : "Account from Rest API", "phone" : "222222" } |
|
Response :-
1 | HTTP/1.1 204 No Content |
3) Delete a record
Method :- Delete
URL:- /services/data/v36.0/sobjects/Account/0019000001hE8apAAC
Response
1 | HTTP/1.1 204 No Content |
4) Retrieve a record
Method :- Get
URL:- /services/data/v36.0/sobjects/Account/0019000001hE8af
Response
1 | {
"attributes" : {
"type" : "Account",
"url" : "/services/data/v36.0/sobjects/Account/0019000001hE8afAAC"
},
"Id" : "0019000001hE8afAAC",
"IsDeleted" : false,
"MasterRecordId" : null,
"Name" : "Express Logistics and Transport",
"Type" : null,
"ParentId" : null,
"BillingStreet" : null,
"BillingCity" : null,
"BillingState" : null,
"BillingPostalCode" : null,
"BillingCountry" : null,
"BillingLatitude" : null,
"BillingLongitude" : null,
"BillingGeocodeAccuracy" : null,
"BillingAddress" : null,
"ShippingStreet" : null,
"ShippingCity" : null,
"ShippingState" : null,
"ShippingPostalCode" : null,
"ShippingCountry" : null,
"ShippingLatitude" : null,
"ShippingLongitude" : null,
"ShippingGeocodeAccuracy" : null,
"ShippingAddress" : null,
"Phone" : "1111111111",
"Fax" : null,
"AccountNumber" : null,
"Website" : "www.salesforce1.com",
"PhotoUrl" : "/services/images/photo/0019000001hE8afAAC",
"Sic" : null,
"Industry" : "Banking",
"AnnualRevenue" : null,
"NumberOfEmployees" : 100,
"Ownership" : null,
"TickerSymbol" : null,
"Description" : null,
"Rating" : null,
"Site" : null,
"OwnerId" : "00590000003XIfkAAG",
"CreatedDate" : "2016-06-02T13:04:35.000+0000",
"CreatedById" : "00590000003XIfkAAG",
"LastModifiedDate" : "2016-06-02T13:04:35.000+0000",
"LastModifiedById" : "00590000003XIfkAAG",
"SystemModstamp" : "2016-06-02T13:04:35.000+0000",
"LastActivityDate" : null,
"LastViewedDate" : "2016-06-02T13:14:38.000+0000",
"LastReferencedDate" : "2016-06-02T13:14:38.000+0000",
"IsPartner" : false,
"IsCustomerPortal" : false,
"Jigsaw" : null,
"JigsawCompanyId" : null,
"CleanStatus" : "Pending",
"AccountSource" : null,
"DunsNumber" : null,
"Tradestyle" : null,
"NaicsCode" : null,
"NaicsDesc" : null,
"YearStarted" : null,
"SicDesc" : null,
"DandbCompanyId" : null,
"CustomerPriority__c" : null,
"SLA__c" : null,
"Active__c" : null,
"NumberofLocations__c" : null,
"UpsellOpportunity__c" : null,
"SLASerialNumber__c" : null,
"SLAExpirationDate__c" : null,
"Accountant__c" : null,
"First_Level_Approval__c" : false,
"Final_Approval__c" : false,
"Old_Account_ID__c" : null,
"Demo__c" : null,
"SumOfOppAmount__c" : null
} |
5) Create multiple record
Method :- post
URL:- /services/data/v34.0/composite/tree/Account/
Request Body :-
1 | {"records" :[{ "attributes" : {"type" : "Account", "referenceId" : "ref1"}, "name" : "SampleAccount1", "phone" : "1111111111", "website" : "www.salesforce1.com", "numberOfEmployees" : "100", "industry" : "Banking" },{ "attributes" : {"type" : "Account", "referenceId" : "ref2"}, "name" : "SampleAccount2", "phone" : "2222222222", "website" : "www.salesforce2.com", "numberOfEmployees" : "250", "industry" : "Banking" },{ "attributes" : {"type" : "Account", "referenceId" : "ref3"}, "name" : "SampleAccount3", "phone" : "3333333333", "website" : "www.salesforce3.com", "numberOfEmployees" : "52000", "industry" : "Banking" },{ "attributes" : {"type" : "Account", "referenceId" : "ref4"}, "name" : "SampleAccount4", "phone" : "4444444444", "website" : "www.salesforce4.com", "numberOfEmployees" : "2500", "industry" : "Banking" }] } |
|
Response :-
1 | {
"hasErrors" : false,
"results" : [ {
"referenceId" : "ref1",
"id" : "0019000001hE8gOAAS"
}, {
"referenceId" : "ref2",
"id" : "0019000001hE8gPAAS"
}, {
"referenceId" : "ref3",
"id" : "0019000001hE8gQAAS"
}, {
"referenceId" : "ref4",
"id" : "0019000001hE8gRAAS"
} ]
} |
6) Update multiple record.
Method :- post
URL:- /services/data/v34.0/composite/batch
Request Body :-
1 | {"batchRequests" : [ { "method" : "PATCH", "url" : "v34.0/sobjects/account/0019000001hE8gOAAS", "richInput" : { "name" : "SampleAccount1", "phone" : "1111111117", "website" : "www.salesforce1.com", "numberOfEmployees" : "100", "industry" : "Banking" } }, { "method" : "PATCH", "url" : "v34.0/sobjects/account/0019000001hE8gPAAS", "richInput" : { "name" : "SampleAccount2", "phone" : "2222222227", "website" : "www.salesforce1.com", "numberOfEmployees" : "100", "industry" : "Banking" } } ] } |
|
Response :-
1 | {
"hasErrors" : false,
"results" : [ {
"statusCode" : 204,
"result" : null
}, {
"statusCode" : 204,
"result" : null
} ]
} |
NOTE:- Please replace id in URL according to your org
Please check below post for more information
1) https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/intro_what_is_rest_api.htm
Let us know if this will help you
<<PREVIOUS NEXT>>
Thanks
Amit Chaudhary
Thank you so much sir.... Its very helpful for us.
ReplyDeletegetting error
ReplyDeletemessage: Cannot deserialize instance of datetime from VALUE_STRING value 2015-12-01 02:45 PM or request may be missing a required field at [line:1, column:25]
errorCode: JSON_PARSER_ERROR
Date Time field should be in the "yyyy-mm-ddTmm:ss:sssz" format.
DeleteIs there any way that we can update an existing record with POST method in salesforce instead of patch?
ReplyDeleteEnrollment arrangement is programming that assists organizations with smoothing out the whole employing process, from finding up-and-comers and assessing their resumes to delegating meetings and sending bids for employment. Such programming additionally offers detailing and investigation highlights. It assists companies with better designating their spending plan, know which and the number of up-and-comers they that need, and gain experiences to further develop their recruiting methods>> recruitment solution
ReplyDeleteThe essay builder is a versatile tool that simplifies the essay writing process. With its user-friendly interface and intuitive features, it allows users to create well-structured essays in no time. The essay builder provides a step-by-step framework, guiding writers through each section of their essay. It's a valuable resource for anyone looking to enhance their writing skills and create compelling essays.
ReplyDelete