function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Malini JeyachandranMalini Jeyachandran 

salesforce contact update through PATCH - rest api

Updating the salesforce field values using patch by constructing the JSON payload for the data which needs updating. How to specify update the records only if the field is blank or null? please help. thanks.
Best Answer chosen by Malini Jeyachandran
Amit Chaudhary 8Amit Chaudhary 8
Yes above code will update mulitple record. If you want to add not overwritten logic in that case you need to create your own API. Please check below post i hope that will help you
http://amitsalesforce.blogspot.in/2016/04/rest-api-in-salesforce-execute-rest-api.html

Let us know if this will help you

All Answers

Amit Chaudhary 8Amit Chaudhary 8
You can try Composite Resources in Salesforce
1) http://amitsalesforce.blogspot.in/2015/05/rest-api-new-resources-summer-15.html

Method :- Post
URL :- /services/data/v34.0/composite/batch
Request Body
{
"batchRequests" : [
    {
		"method" : "PATCH",
		"url" : "v34.0/sobjects/account/0019000001hGWPa",
		"richInput" : { "name" : "SampleAccount1",
						"phone" : "1111111117",
						"website" : "www.salesforce1.com",
						"numberOfEmployees" : "100",
						"industry" : "Banking"
						}
    },
	
	{
		"method" : "PATCH",
		"url" : "v34.0/sobjects/account/0019000001hGWPb",
		"richInput" : { "name" : "SampleAccount2",
						"phone" : "2222222227",
						"website" : "www.salesforce1.com",
						"numberOfEmployees" : "100",
						"industry" : "Banking"
						}
    }
	]
}
NOTE:- Please replace id in URL
"url" : "v34.0/sobjects/account/0019000001hGWPb", ---------- Add real ID here
User-added image

Let us know if this will help you

Thanks
Amit Chaudhary

 
Malini JeyachandranMalini Jeyachandran
Thanks so much. will this update multiple contacts? And what I need if the contact field 'industry' has 'Government' already in salesforce, dont want that field to be overwritten. I want to update only if the field is null or blank, Can I do that ?
Amit Chaudhary 8Amit Chaudhary 8
Yes above code will update mulitple record. If you want to add not overwritten logic in that case you need to create your own API. Please check below post i hope that will help you
http://amitsalesforce.blogspot.in/2016/04/rest-api-in-salesforce-execute-rest-api.html

Let us know if this will help you
This was selected as the best answer
Malini JeyachandranMalini Jeyachandran
Thanks. Using Multiple Organisation slaesforce integration through Oauth , how can I create my Own API to do this? Any insights?