Hot answers tagged

25

Salesforce passes in the HTTPRequest made by the logic your testing into the mock implementation to help with this type of requirement. So in the HttpCalloutMock.respond method implementation. You can call req.getBody() and condition the response based on that, here is an example... @IsTest private with sharing class MultiHttpMockTest { public class ...


20

Here is a working POST example... Http h = new Http(); HttpRequest req = new HttpRequest(); req.setEndpoint(URL.getSalesforceBaseUrl().toExternalForm() + '/services/data/v28.0/sobjects/CurrencyType/'); req.setMethod('POST'); req.setBody('{ "IsoCode" : "ADP", "DecimalPlaces" : 2, "ConversionRate" : 1, "IsActive" : "true" }'); req....


17

Update to this answer, there are 2 workarounds to the missing PATCH verb in HttpRequest that may work in a few specific contexts: If you are calling TO Salesforce, FROM Salesforce (e.g. an integration between two orgs), you can append ?_HttpMethod=PATCH to the endpoint. Note that this is not a feature of the HttpRequest object, it doesn't do anything clever ...


15

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


13

I have something similar in a package I have built - a series of apex classes that make callouts to a third party web service. The expectation is that a customer will then build their own VF controllers to utilize my classes, and the data they return. To get round the issue you raise, I built a globally available method in a class in my managed package that ...


11

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


11

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


9

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


9

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


7

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

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


7

The apex:outputText tag escapes content by default. If you'd like to display HTML content you'll want to set the escape attribute to false. <apex:page showHeader="false" sidebar="false" standardStylesheets="false" controller="GetBlueDotMenu"> <apex:outputText value="{!response}" escape="false"/> </apex:page>


7

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


6

Unfortunately your SOL when it comes to that sort of limit, you're 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.


5

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


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


4

string test = 'test1,test1@gmail.com'; // which will be get from DB and make as CSV string String header = '--'+boundary+'\n'; //boundary is random string String footer = '\n\n--'+boundary+'--'; // blank line separates body/footer String bodyText = 'Content-Disposition: form-data; name="upload";\n' + 'filename="test.csv"\n' ...


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

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


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


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 isn't unique to this limit. System.LimitException is uncatchable and means that your script will be killed, even if it happens inside a try/catch block. I don't know of any good way to handle this for responses within the same context. However, if you make the callout in a different context (JS remoting, etc.) and add some sort of success/error ...


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

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.


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