30

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. Prior to this patch System.debug(UserInfo.getSessionID()); would return 18:44:36:004 USER_DEBUG [1]|DEBUG|00D3A0000000001!ARkAQApQe_Omitted_yGifr....


25

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://releasenotes.docs.salesforce.com/en-us/winter21/release-notes/rn_apex_callouts_patch.htm Pre-Winter 21 Update to this answer, there are 2 workarounds to the missing ...


22

This is how I send attachments. All credits(& explanation) http://enreeco.blogspot.in/2013/01/salesforce-apex-post-mutipartform-data.html @Future(callout=true) public static void uploadFile(Blob file_body, String file_name, String reqEndPoint){ String boundary = '----------------------------741e90d31eff'; String header = '--'+...


19

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 (governor limits) and assign a callback mechanism, to handle response for such callouts. The mechanism is called continuation, wherein all such asynchronous requests ...


18

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 rest of the code for the callout, and mark that with the @future annotation, something like this: public PageReference init() { System.debug('From ...


16

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 pass in the desired HTTP method to use, but then set the request method to POST: req.setHeader('X-HTTP-Method-Override','PATCH'); req.setMethod('POST'); For ...


16

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 AWSS3_GetService extends AWS { public override void init() { endpoint = new Url('https://s3.amazonaws.com/'); resource = '/'; region = 'us-...


15

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 occasionally you will get corruption in the last few bytes of your data. The fix below resolves this issue, I'm posting it here as I'm extremely grateful to have been ...


15

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. This also means that Database.rollback can undo a scheduled job, batch job, queueable, or future method. Also note that any of those methods will prevent you ...


11

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 performing URL redirection. An HTTP response with this status code will additionally provide a URL in the location header field. The user agent (e.g. a ...


9

You can't call out from a pre-release org, since the security rules are different from our production/developer environments.


9

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.


9

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 object, and adding it to the responseBody of the RestResponse. Here's an example: @RestResource(urlMapping='/ServiceName/*') global class SomeService { @...


8

I wrote this test Google Script... Then made sure when I published it I selected this option so it can be accessed anonymously, without requiring Google authentication... Google redirects the response from the published URL to a content serving URL. The Apex HTTP client does not automatically follow redirects, so you have to respond to the HTTP 302 ...


8

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 then doing call out in single run. You have to break thread with @future annotation.


8

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 third-party server: HttpRequest req = new HttpRequest(); req.setEndpoint(endpoint); req.setBody(reportText); req.setHeader('Content-Type','text/csv'); req....


8

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 output something like [{"attributes":{"type":"Account","url":"/services/data/v40.0/sobjects/Account/0010O00001kzzCtQAI"},"Id":"0010O00001kzzCtQAI"}] If it's ...


8

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 for asynchronous code. If for some reason you were able to send more than 6MB/12MB, this was a bug that has since been fixed. It should never have been ...


8

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 languages too. The solution here is to store the configuration for your callout in something like a Map<String, String> or a custom configuration wrapper ...


8

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 if you want to use the automatic XML/JSON conversion support provided by the platform depending on the Accept request header. You can read more about this ...


7

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 HTTPRequest version of the login method appears. Each request and response element gets a constructor that works with a Dom.XmlNode and a corresponding method to ...


7

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 transmitted as part of the view state for a Visualforce page. For example: Transient Integer currentTotal; You can also use the transient keyword in Apex ...


6

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, you need to include the managed package namespace in the REST call URL. For example, if the class is contained in a managed package namespace called ...


6

Looking at the Partner WSDL, the soapAction for the login operation is the empty string. <operation name="login"> <soap:operation soapAction=""/> <!-- .... --> </operation> So you would think that it should be added to the request as such: HttpRequest req = new HttpRequest(); // ... req.setHeader('SOAPAction'...


6

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 suggestible to test the HTTP url from any on the REST applications like POSTMAN before making a decision in salesforce.


6

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 mainly for debugging purposes. This method, originally assumed harmless, can be used to mount an attack known as Cross Site Tracing, which has been discovered by ...


6

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, this means that your page should start off like this: <apex:page controller="xyz" action="{!firstRedirect}" ...> Where firstRedirect determines if there's ...


6

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 happening because of your trigger, but somehow, running a DML update on your Contacts in your @future method is causing your @future method (or perhaps some ...


6

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. When I hit a problem, I debug log the resulting request Salesforce has produced, load it up in soapUI / Chrome REST client and keep hacking at the generated ...


6

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/catch to actually catch the callout exception and then do your DML afterwards to record what the outcome was. If what you really want is to log something before or ...


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