33 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. ...
Daniel Ballinger's user avatar
20 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 ...
Emmanuel BRUNO's user avatar
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 ...
sfdcfox's user avatar
  • 477k
18 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....
sfdcfox's user avatar
  • 477k
17 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 ...
Keith C's user avatar
  • 134k
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 ...
Salesforce Learner's user avatar
9 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 ...
Derek F's user avatar
  • 58.3k
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 ...
Dana Griff's user avatar
  • 1,554
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 ...
sfdcfox's user avatar
  • 477k
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 ...
sfdcfox's user avatar
  • 477k
7 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 ...
Daniel Ballinger's 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 ...
Adrian Larson's user avatar
  • 149k
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/...
Charles T's user avatar
  • 10.9k
7 votes
Accepted

Not able to post data to Http with content type: application/x-www-form-urlencoded

I think you need to URL-encode the parameters in your payload. The password needs it in this instance, and it's worth doing for the username too. So, you would have: String payLoad = 'grant_type=...
Aidan's user avatar
  • 13.5k
7 votes
Accepted

Cannot download large files from Salesforce URL using C#

The root cause of your problem is when you try to fetch image data from /sfc/servlet.shepherd/document/download/{ContentDocumentId} resource, you receive the next response, and only after that a ...
Oleh Berehovskyi's 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, ...
sfdcfox's user avatar
  • 477k
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 ...
Derek F's user avatar
  • 58.3k
6 votes
Accepted

Using basic http authentication to authorize connection

You can't use Basic Authentication with Salesforce. Instead, use the SOAP login() call or the OAuth Username-Password authentication flow.
sfdcfox's user avatar
  • 477k
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. ...
eyescream's user avatar
  • 23.9k
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 ...
sfdcfox's user avatar
  • 477k
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 ...
Travis Naughton's 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 ...
Robs's user avatar
  • 9,067
6 votes
Accepted

How can I create custom HTTP body

We can make this dynamic by defining class structures, i.e.: public class Data { public String website_id; public List<Column> columns; public String date_from; public String ...
Jesse Wheeler's user avatar
5 votes
Accepted

API Callout (apex class) from workflow - You have uncommitted work pending,please commit before calling out

You can't callout during the life cycle of a DML operation directly. This limitation was put in place to prevent excessive row lock times. You can callout and perform DML in the same transaction, ...
sfdcfox's user avatar
  • 477k
5 votes

AWS Signature (version 4) in Apex

The date formatting is wrong in the method "getStringToSign". The day and month must be in 2 digits, and same for hour, minutes... You should debug your code to ensure the string to sign is in the ...
Abdel-Ali B.'s user avatar
5 votes
Accepted

Method does not exist or incorrect signature: [System.HttpRequest].setHeader(Blob)

If you look at the documentation you will see that the only setHeader method available has this signature: public Void setHeader(String key, String value) In HTTP, headers each have a name and value ...
Keith C's user avatar
  • 134k
5 votes
Accepted

Apex Rest Callouts in Trailhead Apex Integration Service Module

I answered this question in this thread. You should post Trailhead related questions in the Trailhead forum for faster assistance.
Jeff Douglas's user avatar
5 votes
Accepted

Making a web service call to Salesforce - Authentication

Salesforce does not support the HTTP Basic Authentication mechanism. All valid API calls that require a session require a valid session ID. The two primary ways of obtaining this are by OAuth or by a ...
sfdcfox's user avatar
  • 477k
5 votes
Accepted

UserName and Password in Request body of apex callout using Named Credentials

When using merge fields you need to actually set the body like string bdy = '{ "username" : "{!$Credential.Username}", "password" : "{!$Credential.Pasword}"}' req.setBody(bdy); The format will ...
Eric's user avatar
  • 53.9k
5 votes
Accepted

A testclass for @RestResource @HttpPost

You can do it in the following way, very similar to common apex class testing @isTest static void testHttpPost() { // prepare test-data //As Per Best Practice it is important to instantiate ...
Oleksandr Berehovskyi's user avatar

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