How can I make a PATCH HTTP Callout from Apex?

I need to make a PATCH http request.

I made the rather incredible discovery today that I can’t set an HttpRequest to use the PATCH method, as when sending the request I get a callout exception:

System.CalloutException “Invalid HTTP method: PATCH”

The work around I’ve found on Stack Exchange and elsewhere is only applicable to a Salesforce Rest API request:

PATCH request using Apex HttpRequest

This is therefore not helpful to me as I’m calling out to a third party.

By what manner of magic can I send a PATCH request from Salesforce?

The only work around I can think of is to not do it from Apex – this is not an option.


Post-Winter 21

As Daniel Ballinger’s mentioned in his new answer below ( – Winter 21 will be bringing support for this at last! See

Pre-Winter 21

Update to this answer, there are 2 workarounds to the missing PATCH verb in HttpRequest that may work in a few specific contexts:

  1. If you are calling TO Salesforce, FROM Salesforce (e.g. an integration between two orgs), you can append ?_HttpMethod=PATCH to the endpoint. Note that this is not a feature of the HttpRequest object, it doesn’t do anything clever with this – rather this is a workaround that Salesforce has in place to allow callers to its REST APIs to do PATCH calls when the caller doesn’t otherwise allow the PATCH verb (which ironically is a problem Salesforce itself suffers). That is to say, this will not help you if you’re calling to a non-Salesforce system. See

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. In the PATCH example, you can replace the PostMethod line with one that doesn’t use override:
PostMethod m = new PostMethod(url + "?_HttpMethod=PATCH");

  1. As noted by @zachelrath in their answer on this question (, setting the header X-HTTP-Method-Override is an option, e.g.
    However, this is a convention that some servers follow in order to support libraries that don’t support certain HTTP verbs, rather than a guarantee of success. This DOES NOT work when calling into Salesforce, Salesforce ignores this header.

If neither of the above options work, it appears to not be possible using Apex alone, without some kind of middleware (e.g. Heroku proxy to turn certain POSTs into PATCHes, or [horror of horrors] a dummy visualforce page to run an XHR) – which you’ve indicated is not an option.

The reason for this looks like it might be because Salesforce behind the scenes is using JDK’s HttpURLConnection, which restricts the http verbs you can use to the HTTP/1.1 defaults. This bug report for your issue in a JDK/HttpUrlConnection context I found is marked as “Won’t Fix” in OpenJDK – Note the description and error message match your issue.

This other StackExchange question indicates it’s a problem across JDKs 6,7, and 8 (and I would presume earlier): – same error phrasing still: Invalid HTTP method: PATCH

Source : Link , Question Author : Nathan Kramer , Answer Author : James Hill

Leave a Comment