Skip to content

Instantly share code, notes, and snippets.

@SalesforceBobLightning
Created July 28, 2018 16:01
Show Gist options
  • Select an option

  • Save SalesforceBobLightning/eb1a1ddaec193145c15ed8fabe411aba to your computer and use it in GitHub Desktop.

Select an option

Save SalesforceBobLightning/eb1a1ddaec193145c15ed8fabe411aba to your computer and use it in GitHub Desktop.
Making Http Callout using Salesforce Apex, with PATCH workaround
public static HttpResponse makeHttpCallout(String url, String method, String body, Map<String,String> headers){
HttpRequest request = new HttpRequest();
Http http = new Http();
if(method == 'PATCH'){
request.setMethod('POST');
url += '?_HttpMethod=PATCH';
} else {
request.setMethod(method);
}
request.setEndpoint(url);
if(String.isNotBlank(body)){
request.setBody(body);
}
if(headers != null){
for(String key : headers.keySet()){
request.setHeader(key, headers.get(key));
}
}
return http.send(request);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment