43
votes
Accepted
Authentication using JWT
In the JWT Bearer OAuth flow, the connected app is identified by the connected app's consumer key (provided in the "iss" parameter of the JWT claims). Pre-authorizing users has very little ...
16
votes
Accepted
RestResource GET with multiple parameters
HTTP GET defines data as a series of query parameters in the URI itself. For example, here’s a URI:
https://na8.salesforce.com/services/apexrest/FieldCase?companyName=GenePoint
So your code will be ...
15
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.
...
13
votes
Accepted
Posting a JSON to REST resource in Salesforce
You can do that in a different way without relying on Native parser of SF to parse your string and provide input in your variable jsonStr. When you pass JSON, make your postMethod parameterless. This ...
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 ...
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.
7
votes
Accepted
RestResource Annotation - What is the urlMapping To?
That tells you the URL path. So when you want to hit your service you would use:
/services/apexrest/CompanyData/
7
votes
Accepted
Improve performance of a rest resource
Processing server-side will always cost performance. The best performance would be if you could return the data without a wrapper. Failing that, the next best option would be to optimize the code.
...
5
votes
Silence the AvoidGlobalModifier warning in @RestResource Apex controller
Your use case needs you to expose a web service. A web service should be always global. I wont worrry much about that warning, as its informative more than obstructing your work. That being said you ...
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 ...
5
votes
How to see JSON response for REST service?
IN exec anonymous simply type:
system.debug(BP_Routes.BP_Routes('APPROPRIATEUSERNAMEHERE'));
and it will debug what is returned. If you like you can serialize it since it is not serialized in your ...
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
...
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 ...
5
votes
Accepted
Rest Resource URL mapping in workbench
The * is a wildcard. It just allows Salesforce to map the URL to your class when a parameter is included. To use your example,
/Accounts/*
can map the URL
/services/apexrest/Accounts/PARAMETER
where ...
4
votes
How to consume a salesforce REST service?
Make sure you encode your email address. The @ character should be encoded to %40.
The following works for me:
string clientId = '3MVG9ZL0ppGP5UNot.A.Real.Client.Id.BWmbi7PQ2vWj1V8Xev....
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 ...
4
votes
How to see JSON response for REST service?
It will be based on the return type you are sending. For example your code is sending ResponseWrapper for HTTP-Post call with URL '/services/apexrest/BP_Routes'
Let's assume you have defined ...
4
votes
Total Record Count in API Call
As per Summer 18 release notes The SOQL Count() Function Doesn’t Count (As Much) Toward Limits.
So now you can make this query and it will be counted as 1. You might need to wait few more days to get ...
4
votes
Accepted
Apex @RestResource returning result inner class exposes private attributes
The docs do (kind of) call this out: (my emphasis)
You can use user-defined types for parameters in your Apex REST methods. Apex REST deserializes request data into public, private, or global class ...
4
votes
Accepted
Salesforce RestResource GET API is unable to identify special characters passed in query string
+ is a "reserved character" in URLs; it represents a space character. Also, @ is a reserved character. To pass in a literal +, use %2B, and for @, use %40, as in:
test%40test%2814%40gmail....
4
votes
Accepted
Why am I getting "Service not found error" when trying to access a @RestResource when it is exists?
For a managed package you will need to ensure you provide the namespace of the package when hitting the custom rest endpoint.
Your url to try hitting would be as below
services/apexrest/namespace/abc/...
4
votes
Accepted
User without create permission can create a custom object from Managed package using Custom Rest API
The default security mode for Apex does not check a user's object or field permissions, it only checks if the user has read, write, or owner permissions as determined by the sharing model. There are ...
3
votes
Accepted
How does Org Namespace in Request URI work from Apex Rest Web Service Test Class?
It's important to give your requestURI a proper-looking value if your code uses it, but strictly speaking, requestURI is a plain String variable, and performs absolutely no validation on its value at ...
3
votes
Accepted
RestResource Annotation - UrlMapping is NOT allowed
urlMapping is meant to be used only on @RestResource (and is required). The notes specify that @HttpPost, for example, must not specify a urlMapping.
Valid
@RestResource(urlMapping='/someUrl/')
...
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; ...
3
votes
Accepted
Use of Wildcard in Apex rest service
If you don't use a wildcard, you need an exact match (e.g. /services/apexrest/Cases will work, but /services/apexrest/Cases/Dog will not). If you do use a wildcard, you can use the contents of the URL ...
3
votes
Accepted
Good way to offer both LWCs and a REST API in the same code?
Initial coding of the KISS solution:
global class Aura {
// Call this from the REST API
public static Object execute(String operation, String requestJson) {
switch on operation {
...
3
votes
Accepted
Create a test class for RestResource class with a response code
It appears all I needed to do was add this to the test class at the start of the method (before the Account acct... line):
RestRequest req = new RestRequest();
RestResponse res = new RestResponse();
...
3
votes
Accepted
Preserve order of params in RestRequest
There's something called the "robustness principle", and it goes like this: be conservative in what you do, be liberal in what you accept from others. Accordingly, most of the things that ...
2
votes
Accepted
RestExplorer in Workbench Get Error?
You have to use following:
https://yourInstance.salesforce.com/services/apexrest/FEApplicationDataById/V1
Workbench conveniently takes care of the ...yourInstance.salesforce.com... part so in the ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
restresource × 95apex × 50
rest-api × 33
apexrest × 31
rest × 22
json × 10
unit-test × 9
rest-service × 7
httppost × 7
api × 4
post × 4
integration × 3
workbench × 3
lightning-aura-components × 2
community × 2
managed-package × 2
webservices × 2
oauth2 × 2
connected-apps × 2
failing-tests × 2
httprequest × 2
deserialize × 2
lightning-web-components × 1
visual-workflow × 1
query × 1