55
votes
Accepted
How to deserialize a JSON list in Apex
Assuming that the JSON data is from a List<Account> in the first place (as it appears to be) you do not need to define your own class but instead can use the Account object type:
String s = res....
34
votes
Accepted
How to correctly return data and errors from REST annotated methods?
Having written a Salesforce managed package app making use of the automatic serialization and deserialization based on the method signature, in future I will avoid that pattern. The primary reason is ...
21
votes
Accepted
Apex Rest Vs Platform Events for Inbound SF integration which one to choose?
UPDATE
I have also discussed this topic with some more detail on on my blog here.
Based on your requirements where:
External System will push data in Salesforce.
My recommendation is to ...
18
votes
Accepted
REST error handling design
You should use standard http status codes.
You can set the status code on RestContext.response anytime before you return.
Salesforce will automatically handle most of these. For example, you don'...
17
votes
Accepted
RestContext.response returns null when run in Test Context
You will have to set up your own RestResponse and RestRequest object.
RestRequest req = new RestRequest();
RestResponse res = new RestResponse();
req.requestURI = 'https://na11....
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 ...
13
votes
Accepted
Help on Invokable Apex Test class and @Future callout Apex test Class
Basically, you need to know about how to test HTTP callouts, and how to test future methods.
Once you've gotten that far, you'll see that the unit test would look like:
@isTest class MakeCalloutTest ...
13
votes
Accepted
URL_NOT_RESET error REST API
test.salesforce.com or login.salesforce.com can be used to first login. Thereafter requests should be made using the instance_url and the access_token that you receive as a response on first login.
...
12
votes
Accepted
Publicly exposed Rest class does not support post method
I found the problem as I make my site secure by HTTPS and was doing a request on HTTP, So the post request was discarded.
Thanks
12
votes
Accepted
Is SOAP API becoming obsolete?
This statement is simply stating that a particular version of the API is only guaranteed to be supported for three years. In other words, salesforce guarantees version compatibility for three years. ...
12
votes
Accepted
How to see JSON response for REST service?
You can head over Salesforce Workbench and use the REST Utility to test the endpoint .
Your endpoint to test will be
/services/apexrest/BP_Routes
Also looks like the method is accepting a string ...
11
votes
Accepted
How I can know who is calling a REST resource?
Regardless as to whether the REST API is exposed behind authentication or not, you have access to the RestRequest within your Apex code. You can use the RestRequest.remoteAddress to discover where the ...
10
votes
Accepted
Check if apex is being run in Rest Resource
You can check if you're in a REST call via:
Request.getCurrent().getQuiddity() == Quiddity.REST
You can read more about the Request object, as well as the possible values for Quiddity.
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 ...
9
votes
Accepted
Variable is not visible
You cannot assign to a property
AccLinks = (kvl != null && kvl.Value__c != null ? kvl.Value__c : 'some_url');
if that property does not have a setter method declared. To make the property ...
9
votes
Accepted
Can API access be limited to only via Apex classes?
In Winter '18, they added an ability to control access to Apex REST Services that is distinct from the API Enabled permission on profiles that provides access to the standard APIs.
This allows you to ...
8
votes
Accepted
Posting data to SFDC via rest API
Yes there is standard way to create any record in Salesforce via POST
/services/data/v34.0/sobjects/OBJECTNAME/
replace OBJECTNAME with object name for which you want to insert the record.
for ...
8
votes
Database SavePoint and Rollback
For the current code shown in the question the database.setsavepoint() and database.rollback() calls have no functional value and could be removed entirely for the same result. You aren't doing any ...
8
votes
Accepted
Apex REST request requires attributes field
According to the JSON documentation:
Object deserialize(String jsonString, System.Type apexType)
Deserializes the specified JSON string into an Apex object of the specified type.
You can use ...
8
votes
what is difference between JSON generator and JSON parser?
The two are opposite features. The JSONGenerator takes data input and outputs JSON strings. The JSONParser takes JSON string input and outputs objects.
If you're sending data to an outside source, ...
8
votes
Accepted
Apex Suicide Scheduler getting stuck as a queued job
Suicide scheduling has never been officially supported, and in fact was explicitly stated that at some point they might choose to limit it to some period of time, such as every 5 minutes minimum:
...
8
votes
Accepted
Is it possible to have multiple POST calls in the same Apex REST class?
You're free to write your resource as:
@RestResource(urlMapping='/abc/*')
Where * indicates a wildcard; this will match any resource that matches this wildcard pattern.
From here, you can then ...
7
votes
Read GET/POST parameters in apex class when service is called from external client
Rather than accept say form encoded parameters it is usually more convenient (for the client and in the Apex code) to accept a JSON string that holds the parameters. For the POST case:
@HttpPost
...
7
votes
Accepted
Future method cannot be called from a future or batch method: Error
As the error states you are calling a future method from another future method .
Your class A calls Class B but I see again you call Class A methods in Class B causing recursion .
Hence would ...
7
votes
Clear platform event limits?
The phrasing is a bit ambiguous in terms of which link you should visit:
For more information see the Resources section.
However, that section does include the below document which I believe answers ...
7
votes
Accepted
Delete multiple records using REST Api
I think endpoint URL should be:
https://ap6.salesforce.com/services/data/v43.0/composite/sobjects?ids=00P0K000016YWusUAG,00P0K000016YWutUAG
7
votes
Apex REST API - Unable to set StatusCode to 429
429 Too Many Requests is not an appropriate status to return from Apex that is processing a REST request, and so presumably that's why the server prevents you from doing so. The relevent RFC indicates ...
6
votes
Posting data to SFDC via rest API
You can use standard REST API as showed by above answer .Also i would like to point out mistake you are doing in the custom REST API
The JSON parameters that you send should match the parmeters of ...
6
votes
Accepted
Apex REST API to return a Map of Maps?
A technique I have used for this sort of case is to directly set the JSON in the response rather than relying on the framework to do the serialization (which as you have noticed has some limitations):
...
6
votes
Accepted
Is every APEX REST class a RESTful service?
Once you annotate your class with @RestResource salesforce takes care of setting status and header.
Even if you set return type as void your client requesting resource will still see the status code ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
apexrest × 593apex × 315
rest-api × 218
rest × 84
json × 56
callout × 55
integration × 45
unit-test × 34
api × 30
rest-service × 30
restresource × 30
webservices × 27
oauth2 × 25
connected-apps × 16
visualforce × 15
community × 14
authentication × 13
post × 12
trigger × 11
force.com-sites × 10
apex-webservice × 9
httppost × 9
code-coverage × 8
lightning × 7
lightning-web-components × 7