Hit a rest url with 'PATCH' method using HTTPRequest Class

Salesforce Feb 28, 2015

Hey Guys, I am back with an interesting scenario wherein I need to make a callout from apex class and the url was a rest resource with method 'PATCH'. As we already know, we have to use HTTPRequest class to make callouts from apex and set method appropriately. Unfortunately, this class doesn't allow to set 'PATCH' as method type and fails on runtime.

There is a trick allowed by salesforce that recognises that the requested resource was called for 'PATCH' method and allow us to make callouts with this. This is given below:

In above method, '?_HttpMethod=PATCH' parameter is added in url and method is changed to 'POST'. Salesforce recognises it in backend and make a PATCH request accordingly.

Hope this help!

Related Tags: