Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in Salesforce by (11.9k points)

I'm using the Play framework to build a web app which integrates with Salesforce via their REST API. In order to send an upsert command to their interface, it seems as if I must use the PATCH method instead of a POST method request. Is it possible to use Play's WSRequest object and change the method type to PATCH instead of POST? If not, how can I use a request object and send a PATCH request instead?

For learning purposes, what is the PATCH method and why does Salesforce enforce use of it instead of a POST method?

1 Answer

0 votes
by (32.1k points)
edited by

I don't know much about what is available in Play, but from the REST API documentation, here is a workaround if your library doesn't support PATCH:

If you use an HTTP library that doesn't allow overriding or setting an arbitrary HTTP method name, you can send a POST request and provide an override to the HTTP method via the query string parameter  _HttpMethod.

For example, to update an Account, this will work with an actual POST request:

.../services/data/v23.0/sobjects/Account/0016000000eEhmxAAC?_HttpMethod=PATCH

As for the reasoning behind using PATCH, it is because PATCH is for partial updates to a resource. That is, you only have to send the fields you are updating. If you were required to send all the fields for a record in updates, PUT would probably be a better choice. POST is generally only for new inserts. Here is an explanation with examples: http://jasonsirota.com/rest-partial-updates-use-post-put-or-patch

To learn in-depth about Salesforce, sign up for an industry based Salesforce Certification.

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94.7k users

Browse Categories

...