13 votes
Accepted

RestResource Class: Set the HTTP Response Status in APEX

RestContext.response.statusCode = 400; You can set any status code defined in RestResponse; simply set RestContext.response.statusCode to any value you'd like from the following list: 200 OK 201 ...
sfdcfox's user avatar
  • 481k
9 votes
Accepted

APEX FATAL_ERROR System.CalloutException: Read timed out

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 ...
Salesforce Learner's user avatar
8 votes
Accepted

System.StringException: Unrecognized base64 character: \

The content you are receiving is not Base64: it is Base64 inside JSON, which you are asking the server to provide to you. Base64 encoding uses the characters [A-Za-z0-9+/]. The backslash and quote ...
David Reed's user avatar
  • 92.1k
6 votes
Accepted

How to work with HttpResponse?

So, the response you are receiving is a JSON string. You can parse it like this: String json = response.getBody(); Map<String,Object> responseMap = (Map<String, Object>) JSON....
Phil Hawthorn's user avatar
5 votes

Details for function Script.Util.HttpResponse

As a note, Script.Util.HttpResponse is not a user function, it is instead the Response Object from the other Script.Util calls. For details to correctly parse information from it, I would look at my ...
Gortonington's user avatar
  • 30.3k
5 votes
Accepted

REST Request is rejected since Winter 23 hit the preview enabled sandbox

Due to enhanced domains been enforced in the Winter 23 release, the hostnames have been updated From orgName--sandboxName.my.salesforce.com To orgName--sandboxName.sandbox.my.salesforce.com I assume ...
mnunezdm's user avatar
  • 890
4 votes
Accepted

HTTP Request Ignoring Body

If you use a HEAD request rather than a GET, the server will return all the headers associated with the URL (and so you can tell if it exists, content type etc), but won't return the body. so instead ...
superfell's user avatar
  • 7,900
4 votes
Accepted

How to make HttpGet service pagination with a limit of a million or more?

Simply put, you can't. While is trivial to build a service that returns, say, up to 50,000 rows, there's simply no mechanism for preserving a QueryLocator across Apex Code transactions, and with one ...
sfdcfox's user avatar
  • 481k
4 votes
Accepted

Parsing JSON response giving null pointer exception

Try it with JSON like: {"stock_prices":[{"code":"AAPL.US","timestamp":1569593940,"gmtoffset":0,"open":220.54,"high":220.96, "low":219.79,"close":220.24,"volume":3397713,"previousClose":219.89, "...
Phil W's user avatar
  • 34.1k
4 votes
Accepted

Problem with testing void HttpRequest

I imagine that you're probably running into an exception like "List index out of bounds: 0" when you run this test. You haven't inserted any Account records as part of your test method. That,...
Derek F's user avatar
  • 59.3k
3 votes
Accepted

Downfalls to using HTTPGet() to see if an asset exists

Firstly, you don't need to print (v) a variable if you are using it inside an AMPscript block. You can change: set @ItemAssetCall = HTTPGet(v(@ItemAsset),true,1,@ItemAssetCallStatus) to: set @...
Eliot Harper's user avatar
  • 16.3k
3 votes
Accepted

JSONParser.getText() results in null but not interpreted as null in if statements

Use VALUE_NULL token getText() Returns the textual representation of the current token or null if there's no current token. Since you explicitly were calling getText() without checking for null ...
Eric's user avatar
  • 54k
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
Accepted

Having trouble deserializing a JSON string of Objects

When you use JSON.deserializeUntyped(data), you need to perform type casting to tell the Apex compiler what kind of object you're working with or you'll get errors because the type Object has no ...
David Reed's user avatar
  • 92.1k
3 votes

How to handle an HTTP response time beyond two minutes?

@Anshul provided an Amazing answer on how to handle callouts in async way. But still the question here is"The maximum callout time is 120,000 milliseconds" i.e You can't go beyond 2mins via any async ...
Pranay Jaiswal's user avatar
3 votes

HTTP call using Salesforce

Blob headerValue = Blob.valueOf(username + ':' + password); String authorizationHeader = 'BASIC ' + EncodingUtil.base64Encode(headerValue); This code is not correct. The automatic "toString" method ...
sfdcfox's user avatar
  • 481k
3 votes
Accepted

System.NullPointerException: Attempt to de-reference a null object Error while parsing XML response

You have <retour> elements without a child <url> element, as for example <retour> <publication>20180917123004</publication> <production>20180917123004</...
David Reed's user avatar
  • 92.1k
3 votes
Accepted

How to handle null keys in JSON response?

You can use the Safe Navigation Operator (?.) to safely ignore null values: accountWrapper.personDeathYear = person.death?.yearOfDeath; This returns null the moment a NullPointerException would ...
sfdcfox's user avatar
  • 481k
3 votes
Accepted

Salesforce Apex Api is Returning response with Escape Character

Don't do this: return JSON.serialize(responseWrapper); Just return responseWrapper; You're returning a String, which Apex is then serializing to JSON by escaping it. You don't need to serialize your ...
David Reed's user avatar
  • 92.1k
3 votes
Accepted

Parsing HTTP JSON Response

When you're traversing throughout your data list, you need to cast each Object to Map<String, Object>. In this Map you can already retrieve id value. Then you should retrieve attributes map, ...
Mariia Illarionova's user avatar
2 votes
Accepted

How to read HTTP Response values from Visualforce correctly?

You can use getBodyDocument instead, which would look like this: Dom.Document doc = response.getBodyDocument(); String tempKey = doc.getRootElement() .getChildElement('Result', null)...
sfdcfox's user avatar
  • 481k
2 votes
Accepted

Why do I get "method doesn't exist or bad signature"?

You are getting this error because your save_search_results method is not static, but your fetch method is. So the latter cannot see the former. Mark save_search_results as a static method as well.
Adrian Larson's user avatar
  • 149k
2 votes
Accepted

How to Create Records from XML Data?

Looks like you are close with 'Option A'. The issue you're running into is that you're not getting deep enough into your XML hierarchy before trying to look for individual orders. Given your input ...
Derek F's user avatar
  • 59.3k
2 votes
Accepted

How to get raw response from .NET force.com toolkit when using QueryAsync

Lets go down the rabbit hole! ForceClient.QueryAsync JsonHttpClient.HttpGetAsync BaseHttpClient.HttpGetAsync protected async Task<string> HttpGetAsync(Uri uri) { var responseMessage = ...
Daniel Ballinger's user avatar
2 votes
Accepted

facing System.CalloutException for HTTP response in test class

The dreaded "uncommited work" exception! For any given transaction, ALL of the Callouts have to happen before ANY of the DML. Looks like your test Class does an insert awbNomOn; followed by a ...
John Thompson's user avatar
2 votes

Writing a Test Class for AuraEnabled HTTPResponse Callouts

The code you posted in your question passes with 100% coverage in my developer org when copied verbatim, except for changing {MY-URL-ENDPOINT} to a real String. As a sanity test, I also wrote a unit ...
sfdcfox's user avatar
  • 481k
2 votes
Accepted

Use the generated Session ID of website to fetch an ID of that external system through Apex class

First you need to deserialize the response and then get the key Map<String,object> responseMap =(Map<String,object>)JSON.deserializeUntyped(authresp.getBody()) ; String token = String....
Tushar Sharma's user avatar
2 votes

Displaying Json Data on Visualforce

Each column needs a simple data value rather than a complex object as its value so something like: <apex:column value="{!pg.Name}"/> <apex:column value="{!pg.Description}"/> ... where ...
Keith C's user avatar
  • 135k
2 votes

How to serialize response in string?

Apex takes care of the serialization if you just return the string from your method. From the documentation: If the method returns void, then Apex REST returns the response in the responseBody ...
Santanu Halder's user avatar
2 votes
Accepted

Apex removes \n from HTTP Response

Try displaying the String with the help of JSENCODE and then replacing \n with <br/> tag. Below is the sample code to display the string on VF page: <apex:outputLabel value="{!SUBSTITUTE(...
Hemant Jain's user avatar
  • 2,765

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