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
14 votes
Accepted

Can we Have two Http Mock Callouts in a single test class method

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, ...
David Reed's user avatar
  • 92.8k
6 votes
Accepted

@IsTest - How to get the RestContext.response from @HttpPost if the post method is not returning

You need to call the actual http method for it to invoke the API and then if you check, it should have the response. @IsTest static void TestBehavior() { RestRequest request = new RestRequest(); ...
metasync's user avatar
  • 1,772
6 votes
Accepted

Trying to turn HTTP 'POST' to 'PUT'; Desire Upsert, Not Just Insert

I'm not sure where you're getting the idea that PUT is the correct verb ("method") here; it should be a PATCH; you'll need to use the _HttpMethod query parameter to set the correct method. Also, to ...
sfdcfox's user avatar
  • 491k
5 votes
Accepted

Test Method for @HttpPost RestResource is not returning expected results

Have a read of Adding SOSL Queries to Unit Tests: To ensure that test methods always behave in a predictable way, any Salesforce Object Search Language (SOSL) query that is added to an Apex test ...
Adrian Larson's user avatar
  • 150k
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

ID query string parameter call to RestResource results in error

Update I was also able to make your HttpPost method work by moving the creation to a @future method. @RestResource(urlMapping='/createLead/*') global with sharing class CreateLeadRest{ @HttpPost ...
Adrian Larson's user avatar
  • 150k
4 votes

ID query string parameter call to RestResource results in error

The reason you're getting this error, is that Lead has required field LastName. It seems that tool you're using is not providing full info, I would recommend to use Chrome extension Postman. That ...
Ilya Lepesh's user avatar
  • 4,125
4 votes
Accepted

Apex Callout HTTP POST with Named Credentials error

You've specified the Content-Type as application/json, but you're using a application/x-www-form-encoded encoding style. You need to make sure they agree with each other. // These do not agree with ...
sfdcfox's user avatar
  • 491k
4 votes

Unable to retrieve security descriptor for this frame error in HTTP POST request SSJS marketing cloud

Try something like this: <script runat="server"> Platform.Load("Core","1.1.1"); var url = “https://mysandbox.com/api/Rest/v1/Authenticate”; var payload = { username: "[email protected]", ...
zuzannamj's user avatar
  • 14.4k
4 votes

How Do I Send an HTTP POST API Call Through a Script Activity Using Basic Auth?

You need to base64 encode your username and password like this: var user = 'foo'; var password = 'bar'; var auth = 'Basic ' + Platform.Function.Base64Encode(user+':'+password); var header = '...
Lukas Lunow's user avatar
  • 21.4k
4 votes
Accepted

SSJS HTTP.Post throws error instead of returning status code

The resulting object you are getting there is from your Catch statement, not the HTTP.Post or HTTPPost error. This means that there is a syntax error that is causing the function to error, not an ...
Gortonington's user avatar
  • 30.6k
3 votes
Accepted

Testing a REST Service POST method question

1) Does this look right?? All the examples for Post methods that I see are sending the primitives as parameters into the POST method, as opposed to one of these user-defined classes that the Guide's ...
sfdcfox's user avatar
  • 491k
3 votes
Accepted

Can we use a map in HttpPost to make our code shorter? (too many fields and we can add more in future)

you can create create WrapperClass for Ticket, create JSON object and send it as param of request @HttpPost global static Ticket__c postT(TicketWrapper wrapper){ Ticket__c thisT = wrapper....
Oleksandr Berehovskyi's user avatar
3 votes
Accepted

Why am I not able to parse valid XML straight from the Salesforce Documentation, but JSON works fine?

I figured it out - I needed to go into the 'Headers' button in Workbench and change the Content-Type: application/JSON; charset=UTF-8 Accept: application/JSON to Content-Type: application/xml; ...
rmarq423's user avatar
  • 967
3 votes

How to send error from HttpPost to Callout if ExternalID is the same?

you can do SOQL query on Item__c filtering by ExternalID__c field. If result is not empty, then set statusCode to relevant one. You can find list of all status codes here. do not set RestContext....
Oleksandr Berehovskyi's user avatar
3 votes

Execute HttpRequest as a different user

Create a Named Credential with the authenticating user = Integration User Do an APEX Http Callout that references the named credential callout:thenamedcred/restofpath to an Apex REST service that ...
cropredy's user avatar
  • 71.4k
3 votes
Accepted

dynamic json body as http post request

You need to pass the parameters to GetUrlRequest by changing it to method: public class RequestWrapper { public static GetUrlRequest GetUrlRequest(String cId, String sBC, String pur, abc abc, ...
salesforce-sas's user avatar
3 votes

Possible to Authenticate an incoming Webhook for use with Post REST Service

The best secure way would be to use a Connected App and Server-Server flow It is always better to authenticate to Salesforce and reach into Salesforce using a connected app. However, as you pointed ...
Mohith Shrivastava's user avatar
3 votes
Accepted

System.TypeException: Invalid decimal in Rest Resource @HttpPost

The error is telling you exactly what is wrong. System.TypeException: Invalid decimal: 30,000 30,000 is not a valid numeric literal in Apex. (The comma, specifically, is disallowed). Consider ...
David Reed's user avatar
  • 92.8k
2 votes
Accepted

HTTP GET method Error

The error's coming from here: base64Data = EncodingUtil.base64Encode(image); In your HttpCalloutMock implementation, you need to remember to call setBodyAsBlob, since you're calling getBodyAsBlob. ...
sfdcfox's user avatar
  • 491k
2 votes
Accepted

REST SERVICE - Unexpected parameter encountered during deserialization

This certainly looks like a problem in your JSON serialization implementation in your Java program . Assuming you are using JSON.simple imports like below import org.json.simple.JSONObject; The ...
Mohith Shrivastava's user avatar
2 votes
Accepted

HTTPPost2 send form data

You will need to use the Content-Type "application/x-www-form-urlencoded" instead of "multipart/form-data".
Eliot Harper's user avatar
  • 16.5k
2 votes

INVALID_SESSION_ID error when external app is calling GETmethod on salesforce

First you need to get the access token from the Connect app tokens. Here is a sample code for your reference public class oAuth_Controller{ private auth_response rt; public pagereference ...
Tushar Sharma's user avatar
2 votes
Accepted

HTTP POST Request with @future and schedulable

You have to explicitly call your future method with each sales order number found by your scheduler. Since your execute() method performs a query and then does no work, you're not going to see a ...
David Reed's user avatar
  • 92.8k
2 votes
Accepted

How to create HTTP end-point which accepts POST data in Salesforce

You still set up an ApexRest endpoint. There's nothing magic about it that requires JSON nor XML. You can whip up a simple demo to prove ApexRest is sufficient for your needs: @RestResource(...
Adrian Larson's user avatar
  • 150k
2 votes
Accepted

Callout REST HttpPost: how to create an object with all fields?

You are parsing SObject here public static App__c ParseRequest(RestRequest req) { App__c app = new App__c(); String body = req.requestBody.toString(); app = (App__c)JSON....
Barış Arslan's user avatar
2 votes

Test for HttpPost service: how to take JSON body for test?

The only real differences between testing an Apex webservice, and testing a "normal" Apex class is that you'll be providing input via RestContext.request, and gathering output via RestContext.response....
Derek F's user avatar
  • 61.6k
2 votes

How can I send an error from HttpPost to Callout if ExternalID is the same?

External ID and Unique ID both are different. You can have duplicate values in External ID field if its not clicked as Unique. Src: https://help.salesforce.com/articleView?id=000005395&language=...
Pranay Jaiswal's user avatar
2 votes
Accepted

Unable to process HTTP return codes except 200

You can get that, but you need to use ampscript and make your request with HTTPPost2.Parameter 4 defines if it should fail on error. Set it to false. I'm not 100% sure what HTTP Status codes are ...
Mateusz Bartkowiak's user avatar

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