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

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

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!

Lakshay Katney Avatar

Lakshay Katney

Saleforce developer by profession but I like to work with various technologies.I blog about Force.com, Hybrid Apps, PhoneGap, AngularJS, BackboneJS, JavaScript in general. I am Angular & NodeJS fan.

Read More
Share this page
Latest 15 Posts

100%