32 votes

Session_ID_Remove Issue in API callouts in Salesforce

Response from the Salesforce Security Team: Since Summer '17 the SessionId will no longer be returned in Debug logs. Instead in its place, SESSION_ID_REMOVED will be returned. e.g. ...
user avatar
27 votes
Accepted

How can I make a PATCH HTTP Callout from Apex?

Post-Winter 21 As Daniel Ballinger's mentioned in his new answer below (https://salesforce.stackexchange.com/a/317712/2429) - Winter 21 will be bringing support for this at last! See https://...
user avatar
  • 1,294
20 votes
Accepted

System.CalloutException: You have uncommitted work pending

You're trying to insert a new case record and then make the call out — the case is your uncommitted work in this instance. You should insert the case, and then call a new method which contains the ...
user avatar
  • 24.7k
19 votes
Accepted

How to handle an HTTP response time beyond two minutes?

Salesforce now allows Apex developers to invoke Asynchronous Callouts. This means that now, developers can initiate callouts from within Salesforce which can respond back in more than 2 minutes (...
user avatar
  • 2,569
18 votes
Accepted

AWS Signature (version 4) in Apex

Here's a gist that shows the basic framework that I developed. To actually implement a sub-service using this framework, you simply need a couple of extra steps, outlined here: public class ...
user avatar
  • 434k
17 votes
Accepted

Does queueing a future method count as DML?

Using System.enqueueJob, Database.executeBatch, System.scheduleBatch, System.enqueueJob, and @future methods all modify the state of the database, so for purposes of callouts, count as a DML operation....
user avatar
  • 434k
16 votes

Post multipart without Base64 Encoding the body

Fix for occasional corruption when uploading a file from Salesforce using multipart mime. The Salesforce solutions for multipart mime so far have left one problem outstanding, in that very ...
user avatar
16 votes

How can I make a PATCH HTTP Callout from Apex?

I had this same experience recently when trying to do a callout to the Google Calendar API, and apparently there's a common practice of servers listening for an X-HTTP-Method-Override header where you ...
user avatar
  • 9,363
16 votes

HttpCallout error [StatusCode=302]

Some HTTP client code handles this automatically but in Apex you have to do the work yourself. Documentation about HTTP 302 explains: The HTTP response status code 302 Found is a common way of ...
user avatar
  • 130k
16 votes
Accepted

Create JSON using apex

It depends on what you really want to do : if it's just about serializing an object, the JSON class will be enough by itself. System.debug(JSON.serialize( [Select Id from Account limit 1] )); will ...
user avatar
9 votes
Accepted

HTTP method DELETE doesn't support output

I'd suggest you need to avoid the call to setBody() when making a DELETE call I doubt DELETE permits an http body of any size.
user avatar
  • 3,503
9 votes
Accepted

APEX FATAL_ERROR System.CalloutException: Read timed out

We can't increase the timeout more than 120 sec since that is the maximum limit. The only workaround is to modify the query on the external webservice application to respond within 120 secs. Its ...
user avatar
9 votes

Apex HttpMethod with two possible returning types

The response you return has to be of type Blob, so it doesn't matter what you return in the function. The way to return an object is by serializing your object as a JSON file, convert it to Blob ...
user avatar
  • 1,514
8 votes

System.CalloutException: You have uncommitted work pending

One of the main reason of this exception is that you are doing some CRUD operation (create,read,update,delete) in your code in same context of running code, means you are doing some DML operation and ...
user avatar
  • 22.2k
8 votes

Missing SOAP action header

Looking at the Partner WSDL, the soapAction for the login operation is the empty string. <operation name="login"> <soap:operation soapAction=""/> <!-- .... --> ...
user avatar
8 votes
Accepted

send a Report as a CSV/TEXT through HttpRequest

You can get the contents of the report by using a PageReference: String reportText = new PageReference('/'+reportId+'?csv=1').getContent().toString(); From there, you can send the data to your ...
user avatar
  • 434k
8 votes
Accepted

Issue while uploading file greater than 5MB

The actual limit is going to be closer to 4,500,000 bytes before encoding. Note that it has never been possible to send more than 12,000,000 bytes of data in a single transaction, and even then, only ...
user avatar
  • 434k
8 votes
Accepted

JSON Serialize and Deserialize on HttpRequest

There are certain classes that are not serializable, and HttpRequest is one of them. I can't seem to find supporting documentation, but from what I recall this is a pretty common constraint in other ...
user avatar
  • 48.3k
8 votes
Accepted

Apex HttpMethod with two possible returning types

Another common solution is to have a top-level DTO that contains the other two DTOs: public class Response { public ResponseDTO response; public ErrorDTO[] errors; } This is particularly useful ...
user avatar
  • 434k
7 votes
Accepted

How to create HttpRequest body as plain string from WSDL?

The FuseIT Wsdl2Apex tool can generate HttpRequests using the DOM classes. To do this you need to select the HTTP Request option for the required methods. Here is an example of how the generated ...
user avatar
7 votes
Accepted

I want to pass an HttpRequest object to a Class that implements the Queueable interface

Remove the transient keyword. It causes the variable not to get serialized. Using the transient Keyword Use the transient keyword to declare instance variables that can't be saved, and shouldn't be ...
user avatar
  • 143k
7 votes

Does queueing a future method count as DML?

It doesn't count as DML, however, queued asynchronous actions enter a queue to be executed after the present transaction. If the Apex transaction rolls back, so does the queue. You could use try/...
user avatar
  • 10.6k
6 votes
Accepted

Get full URL (including querystring) from an apex REST endpoint

The base url is quite clearly stated in the documentation : Apex REST methods can be used in managed and unmanaged packages. When calling Apex REST methods that are contained in a managed package, ...
user avatar
6 votes
Accepted

Using HTTP Trace in Salesforce

So, according to OWASP having the TRACE support on your server is generally a bad idea. TRACE: This method simply echoes back to the client whatever string has been sent to the server, and is used ...
user avatar
6 votes
Accepted

Update my visualforce page based on a third party http response

That's not how OAuth is intended to be used. What you should be doing is calling that endpoint with a callback URL set to a VF page that can accept the OAuth parameters when successful. Basically, ...
user avatar
  • 434k
6 votes
Accepted

Not able to call @future from @future

The problem you're having isn't that you can't call an @future method from a trigger, but rather that you end up trying to call an @future method when you're already in an @future context. It isn't ...
user avatar
  • 48.3k
6 votes
Accepted

HTTP 400 Bad Request response while testing Thomson Reuters World Check One API

If you don't control the target website and can't access logs there - you could try sending the request to a debug logging endpoint. I tend to do it when I'm building new SOAP / REST integrations. ...
user avatar
  • 23.6k
6 votes
Accepted

http request in a for loop

There's no problem with this code as written, but I suggest you set the mock in your unit test method, not the class itself. As written, you won't be able to get 100% coverage. Make sure you save any ...
user avatar
  • 434k
6 votes

How do I POST HTML Form Data coming from an externally hosted webpage to a Data Extension on Salesforce Marketing Cloud

There are a couple of different options. You could use Email Studio Web Collect. https://help.salesforce.com/articleView?id=mc_es_email_studio_web_collect.htm&type=5 It's basic and and has a ...
user avatar
6 votes
Accepted

How to send a PATCH HTTP Callout from Apex to Salesforce Tooling REST API

Use ?_HttpMethod=PATCH in the request URL. public static HttpResponse makeHttpCallout(String url, String method, String body, Map<String,String> headers){ HttpRequest request = new ...
user avatar
  • 8,272

Only top scored, non community-wiki answers of a minimum length are eligible