Hot answers tagged

27

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 ...


18

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-...


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 ...


12

Below is a pattern I use to vary the status code returned. It only maps two categories of exceptions but if you need to you can add more. Note that only status codes from this list can be returned - you can't return other status codes. By catching Exception it handles most unplanned errors (but can't catch governor limit exceptions), and the purpose of the ...


11

Yes, you can, using either of two techniques. Your HttpCalloutMock's respond() method can inspect its inbound HttpRequest, and construct a different response based on which endpoint is being called, the parameters passed, etc. This allows you to write a single class that returns responses for multiple callouts made in sequence in your code under test. ...


10

You can use the setBodyAsBlob(Blob someBlob) method on HttpRequest to send a raw blob in an HTTP request. If you need to send a mime multi-part request, then that's harder as there's no good way to glue together the string mime part headers and the binary data (you can at this point, base64 encode the payload to work around that).


9

The issue lies with the autogenerated GUID for the External/Customer Key (those names are interchangeable) and the Object ID GUID, which is not visible in the UI. For your particular call, if you are grabbing BBDD0F10-94A1-4CD6-B7A2-32FEB671E44F from the UI, then your API call should be https://www.exacttargetapis.com/hub/v1/dataevents/key:BBDD0F10-94A1-...


9

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


9

Here ya go for everyone needing to know this. Here's how it is done: <p id="date" style="font-family:Georgia, serif; color:#446c5a; font-style:italic; font-size:16px; padding-top:0px; margin-bottom:0;">%%xtmonth%% %%xtday%%, %%xtyear%%</p> %%[Var @curdate, @url SET @curdate = Format(Now(), "MMddyyyy") SET @url = Concat("http://...


8

For servers that accept a Transfer-Encoding header, you can set the appropriate request header and send the data as Base64-encoded. Not all servers support this mode, however. It is also possible to send it as a multipart form message and set the Content-Transfer-Encoding header appropriately for servers that accept multipart form data with base64 encoding. ...


7

Yes, the customer key in this case refers to the external key that's specified when you create the extension as shown below.


7

Unfortunately you're SOL when it comes to that sort of limit, your only route is going to be moving the operation off Salesforce. One option would be to create a Heroku app with a single endpoint that takes the attachment Id. The endpoint can then retrieve the attachment and then upload it to the 3rd party server.


7

No, that's nor quite right. Imagine callout as animal and Http as cat, it's a subclass, not the actual class. What I mean is you have 2 types of callouts in Apex: Http http = new Http(); http.send(/*...*/); and WebServiceCallout.invoke(/*...*/); Here is the documentation link.


6

1) Please vote for the PATCH verb to be added here: https://success.salesforce.com/ideaView?id=0873A000000PST0QAO 2) In case the URL parameter override does not work, you can attempt using an HTTP Header to override the method: req.setMethod('POST'); req.setHeader('X-HTTP-Method-Override', 'PATCH'); More info here: https://docs.oracle.com/cloud/...


6

To my knowledge, the following are the limitations: Callout Limits: Currently there is not much documented, but there is a 'limit' of 2000 SOAP calls per minute. The other consideration is that if your Automation using this script is a huge resource draw, you can see the rest of your Enterprise slow to a crawl and likely will draw the attention of SFMC that ...


5

Webservice specifically refers to a SOAP implementation, and HTTP simply refers to any service that uses the HTTP protocol, the most popular being REST and SOAP. The difference is the "payload" of the body and some different headers. Both start off with the standard HTTP format: ACTION PATH VERSION Header: Value <repeat-as-necessary> <body> ...


5

You can use response.getHeader('Set-Cookie') to find the cookies set by the responding site. HttpRequest request1 = new HttpRequest(); request1.setMethod('GET'); request1.setEndpoint('http://www.google.com/'); HttpResponse response1 = new Http().send(request1); String cookies = getResponse.getHeader('Set-Cookie'); //semicolon-delimited keys and values ...


5

TLS 1.1 and 1.2 are supported regardless of when you enable this critical update. TLS 1.0 will not be automatically disabled in your Production Instance until March 4, 2017, at 9:30 AM PST. Until that date, you can still use the old TLS 1.0 protocol. Note that the date for automatic disablement in Sandbox Instances has already passed. See TLS 1.0 ...


5

Please refer the Salesforce Spring ’17 Release Notes, this was implemented to enhance security of the platform. Updated Referer Header When loading assets outside of Salesforce, or navigating outside of Salesforce, the referer header shows only salesforce.com rather than the entire URL. This feature eliminates the potential for a referer header to reveal ...


4

1. Login Procedure For the login procedure POST is used. Here you have to add the parameter format=xml to your request body. POST https://test.salesforce.com/services/oauth2/token HTTP/1.0 content-type: application/x-www-form-urlencoded; charset=utf-8 content-length: 256 accept: */* user-agent: Whateva host: test.salesforce.com grant_type=password&...


4

Finally after analyzing the request sent by the browser and Hurl.it it seems that I was missing a header called Accept-Encoding whose value was 'gzip'. req.setHeader('Accept-Encoding', 'gzip'); Now it is returning the JSON response it was suppose to.


4

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 right format (especially the date/time): http://docs.aws.amazon.com/general/latest/gr/sigv4-create-string-to-sign.html


4

TLS is the transport layer which encrypts your connection while commenting between Server - Client. So, eventually there have been cryptographic improvements in TLS. Previously it was TLS 1.0 which most of the browser and server support. After this new improvement came which is TLS 1.1 (TLS 1.2 is current) The basic difference is TLS 1.0 supported the ...


4

Your assumption: I asume that the last step, as the Doc says cannot be performed, since I cannot do an insert after a HTTP Callout. is not correct You can do a dml after the callout just not before. So after your callout it is perfectly fine to perform DML. If you are making several callouts, store the results in a collection and write them after all ...


4

There was a talk on using Named Credentials to call back into the same Salesforce org at Dreamforce this year 2018: Named Credentials: Securing and Simplifying API Callouts. Looks like it was the same talk as 2017 The example was given against the SOAP Metadata API, but the general principal should be the same. You can use the {!$Credential.OAuthToken} ...


4

You need to annotate your POST handler method with the @httpPost decorator. That way Salesforce knows to run that method when the REST Request method from outside is set to "POST". It should look like this: @httpPost global static String NewLead(...){...} Here's the Documentation


3

This appears to be a bug. Please file a case with support. When I do exactly as you state, I get the exact same behavior. In attempting to just pass a parameter, I left the setAnchor call in my code, and the anchor was preserved in the URL as follows: https://c.na11.visual.force.com/apex/testredirect2?testparam=test#test But even here, PageReference....


3

This is a known issue. According to Rich Unger, the solution may be to "Run All Tests" or click the "Compile All Classes" link in the Apex class list. Take a look at this blog post and the comments at the bottom of the page for more info.


3

This is nothing to do with Salesforce .It is your chrome browser or mozilla blocking this .Modern day browsers have gone smart . Check the below knowledge article link from Salesforce on this issue https://help.salesforce.com/apex/HTViewSolution?id=000213361&language=en_US Having said that browsers also provide mechanism to load unsafe script at your ...


3

Spring '15 introduced a new feature: Make Long-Running Callouts from a Visualforce Page. Here's the relevant code from the page: public with sharing class ContinuationController { // Unique label corresponding to the continuation public String requestLabel; // Result of callout public String result {get;set;} // Endpoint of long-running ...


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