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


8

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


6

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(); RestResponse response = new RestResponse(); request.requestURI = '/services/apexrest/SampleAPI'; request.httpMethod = 'POST'; request....


6

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 assign the correct account, you need the account's External ID (or it's actual other-org ID), and specified in the payload. // Define upsert field and value ...


5

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 global static void doPost() { insertLead(RestContext.request.params.get('id')); } @future public static void insertLead(String id) ...


4

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 method returns an empty set of search results when the test method executes. If you do not want the query to return an empty list of results, you can use the Test....


4

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 will give HTTP 500 and: [ { "errorCode": "APEX_ERROR", "message": "System.DmlException: Insert failed. First exception on row 0; first error: ...


3

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.converttoSobject(); insert thisT; return thisT; } global class TicketWrapper{ public String title {get; set;} public String whattime {get; set;} ...


3

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; charset=UTF-8 Accept: application/xml


3

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.response.responseBody and use return at same time, as return result will be set as response body. If the method returns void, then Apex REST returns the ...


3

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 executes in your own org. The Apex Rest Service will be invoked as if run from Integration User The Apex REST service can then do database updates An alternative ...


3

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 each other req.setHeader('Content-Type','application/json'); req.setBody('customerNumber='+EncodingUtil.urlEncode(cN, 'UTF-8')+'&requireGenericEquivalent='+...


3

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, cbl cbl){ return new GetUrlRequest(cId,sBC,pur,abc,cbl); } public class abc { public String ab; public String cd; public ...


3

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: "test@test.com", password: "testtbot1", privatekey: “0lemon9087” }; var contentType = “application/json”; try { var request = HTTP.Post(url, contentType, ...


2

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. class FBIntCalloutMock implements HttpCalloutMock { public HttpResponse respond(HttpRequest req) { HttpResponse res = new HttpResponse(); res....


2

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 proper way to convert to JSON string would below StringEntity body = new StringEntity(applicant.toJSONString()); Alternatively use Jackson for faster JSON to ...


2

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 auth_Step_1(){ String auth_url = 'https://login.salesforce.com/services/oauth2/authorize'; String params = '?response_type=code' + ...


2

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 example uses. I could do that, but the number of parameters is substantially larger than what I have provided in my example. Yes, you can use non-primitives. ...


2

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 the Rest Context RestRequest req = new RestRequest(); RestResponse res = new RestResponse(); req.requestURI = '/services/apexrest/Something'; //...


2

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 result of it - the query contents are simply discarded. There is a broader architectural issue, though. The limit for future method invocations in a transaction is ...


2

To start with: clientId should be client_id clientSecret should be client_secret I would use form-data to post the payload (I've only got this request to work using form-data). Note, the other issue that you are going to hit is that the response payload is JSON and AMPscript can't parse JSON. Fortunately, Guide Template Language (or GTL) can help you out ...


2

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(UrlMapping='/Demo/*') global class Demo { @HttpPost global static void doStuff() { String body = RestContext.request.requestBody.toString(); ...


2

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.deserialize(body, App__c.class); return app; } But the json you send is like below {"title":someTitle,"description":someDescription,"skills":someSkills}...


2

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. The following is an excerpt from one of my own tests for an Apex webservice in my org: RestContext.request = new System.RestRequest(); RestContext.response =...


2

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=en_US&type=1 That being said, you have to make your external ID field as unique from Object Setup. If you try to insert with same UnqiueID field you will ...


2

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 = 'Authorization: ' + auth;


2

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 error on the server receiving the call. What the two SSJS HTTP functions are referring to as an error is if the call returns an issue from the server (server says ...


1

Since I assume your postman call works while your Apex one doesn't, I suggest you change it slightly so that you can find the problem in your JSON. What I would do is insert the headers as such and send a raw JSON via Postman, that way you can play around with the JSON and try to find the bug. As of your current code, it's fine. and the response ...


1

Rookie Mistake - There was a field in the Patch that I'm not allowed to update and since I was dealing with the same object and switching between a POST and a PATCH based on whether the object already existed I was not aware of this field level restriction.


1

Let's make few assumptions first before I answer this question. Your client wants to use JS to create records in Salesforce org. Not sure why using JS with Http is such a hard requirement. Anyway, we will proceed ahead with this assumption. You are using either Classic or Lightning. The best way to use JS can differ based on the context. For example, in ...


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