Skip to main content
New
Stack Overflow Jobs powered by Indeed: A job site that puts thousands of tech jobs at your fingertips (U.S. only). Search jobs
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
19 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
  • 494k
18 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
  • 136k
10 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
  • 62.1k
9 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.7k
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,576
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
  • 494k
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
  • 494k
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
  • 150k
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
  • 11k
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
  • 494k
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
  • 62.1k
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
  • 494k
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
  • 24.1k
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
  • 494k
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,356
6 votes
Accepted

Best Practice deserialize a JSON to avoid heap size limit

The heap limit is more of a "suggestion" than a hard rule. Having 13 MB of used heap isn't a big deal if you only do so briefly. However, there is a hard limit for strings; one single string cannot ...
sfdcfox's user avatar
  • 494k
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
6 votes
Accepted

Retrieve Request Method from HTTP Request Header

You're looking for Platform.Request.Method(), that's listed in the HTTP Properties Functions article. Here's an example snippet that will extract most of the data you might need: <script runat=&...
Rafał Wolsztyniak'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
  • 494k
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
  • 494k
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
  • 54.2k
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
5 votes
Accepted

How can I write test classes for HTTP callouts which has checks for multiple status codes?

Write test-method for each possible scenario. For example, you have the following conditions: if(A) { if(subA) { do A and subA; } else { do A and not SubA; } } else { ...
Oleksandr Berehovskyi's user avatar
5 votes

Create JSON using apex

I've never used this myself, but if you need more flexibility than the regular serialize method you can use JSONGenerator. Some sample code taken from the Apex Developer Guide: public class ...
IllusiveBrian's user avatar
5 votes
Accepted

System.CalloutException: Unable to tunnel through proxy. Proxy returns "HTTP/1.1 503 Service Unavailable"

https://Test.com:50001/RESTAP/BGN/PRDV/CREATE This URL looks like the one accessible only within company's network. Ideally, your integration endpoint should be something which is accessible over ...
Cloud Man's user avatar
  • 1,355

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