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
Nitin Kumar 162Nitin Kumar 162 

Httprequest.setMethod() not support PATCH method

There is an issue with my HTTP request.salesforce is not allowing me to use PATCH method.
Below are the notification which i get after calling a patch.

System.CalloutException: Invalid HTTP method: PATCH.

when we override the method with patch
req.setHeader('X-HTTP-Method-Override','PATCH');
req.setMethod('POST');
Then i am geeting below notification.
System.HttpResponse[Status=Method Not Allowed, StatusCode=405]
Best Answer chosen by Nitin Kumar 162
v varaprasadv varaprasad
Hi Nitin,

In callouts, we don't have Patch Method in salesforce.
https://trailhead.salesforce.com/en/content/learn/modules/apex_integration_services/apex_integration_rest_callouts

In RestApi We have PATCH Method(REST Service).
https://www.youtube.com/watch?v=7PaDtgPLH90&list=PLXzeMOBB7cjcOJnkB8Am-rc_ps3661neg
https://trailhead.salesforce.com/content/learn/modules/apex_integration_services/apex_integration_webservices


Hope this helps you!
If my answer helps resolve your query, please mark it as the 'Best Answer' & upvote it to benefit others.


Salesforce Freelance Consultant/Developer/Administrator/Trainer
@For Salesforce Project Support: varaprasad4sfdc@gmail.com


Salesforce latest interview questions and training videos :
https://www.youtube.com/channel/UCOcam_Hb4KjeBdYJlJWV_ZA?sub_confirmation=1

 

All Answers

Rutger GernandtRutger Gernandt
That response does not mean that Salesforce is not allowing you to make that call with this method in the header, but rather that the other end is not allowing the method for the endpoint you are calling. Could be two reasons: either the service does not allow this method (I guess you looked this up from the reference docs so that is not very likely) or the other end has no support for the methode overide header.

So unless you have control over the service you are calling, the only solution would be to create a custom fowarding script that you run on your own server I guess. 
v varaprasadv varaprasad
Hi Nitin,

In callouts, we don't have Patch Method in salesforce.
https://trailhead.salesforce.com/en/content/learn/modules/apex_integration_services/apex_integration_rest_callouts

In RestApi We have PATCH Method(REST Service).
https://www.youtube.com/watch?v=7PaDtgPLH90&list=PLXzeMOBB7cjcOJnkB8Am-rc_ps3661neg
https://trailhead.salesforce.com/content/learn/modules/apex_integration_services/apex_integration_webservices


Hope this helps you!
If my answer helps resolve your query, please mark it as the 'Best Answer' & upvote it to benefit others.


Salesforce Freelance Consultant/Developer/Administrator/Trainer
@For Salesforce Project Support: varaprasad4sfdc@gmail.com


Salesforce latest interview questions and training videos :
https://www.youtube.com/channel/UCOcam_Hb4KjeBdYJlJWV_ZA?sub_confirmation=1

 
This was selected as the best answer
Santosh Reddy MaddhuriSantosh Reddy Maddhuri

Hi NitintKumar 162,


Use   req.setMethod('PUT'); and not   req.setMethod('PATCH'); your code will work.

Mark this as correct answers if it works.This will help others.


Regards,

Santosh,