Created
July 28, 2018 16:01
-
-
Save SalesforceBobLightning/eb1a1ddaec193145c15ed8fabe411aba to your computer and use it in GitHub Desktop.
Making Http Callout using Salesforce Apex, with PATCH workaround
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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