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....
Keith C's user avatar
  • 135k
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 ...
Keith C's user avatar
  • 135k
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 ...
Jayant Das's user avatar
  • 30.3k
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'...
NSjonas's user avatar
  • 10k
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....
Ashwani's user avatar
  • 22.6k
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
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 ...
sfdcfox's user avatar
  • 481k
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. ...
Thamilhan's user avatar
  • 302
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
ashishcloud's user avatar
  • 1,050
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. ...
sfdcfox's user avatar
  • 481k
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 ...
Mohith Shrivastava's user avatar
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 ...
Phil W's user avatar
  • 34.1k
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.
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
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 ...
David Reed's user avatar
  • 92.1k
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 ...
Kris Goncalves's user avatar
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 ...
Himanshu's user avatar
  • 10.5k
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 ...
Daniel Ballinger's user avatar
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 ...
Ilya Lepesh's user avatar
  • 4,115
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, ...
sfdcfox's user avatar
  • 481k
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: ...
sfdcfox's user avatar
  • 481k
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 ...
sfdcfox's user avatar
  • 481k
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 ...
Keith C's user avatar
  • 135k
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 ...
Mohith Shrivastava's user avatar
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 ...
Adrian Larson's user avatar
  • 149k
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
Ayub's user avatar
  • 3,443
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 ...
Thomas Taylor's user avatar
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 ...
Mohith Shrivastava's user avatar
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): ...
Keith C's user avatar
  • 135k
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 ...
Mohith Shrivastava's user avatar

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