Skip to main content
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 ...
Derek F's user avatar
  • 63.2k
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 ...
Tushar Sharma's user avatar
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. ...
Thamilhan's user avatar
  • 322
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 ...
Pranay Jaiswal's user avatar
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
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
  • 500k
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/
Adrian Larson's user avatar
  • 151k
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. ...
sfdcfox's user avatar
  • 500k
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 ...
Pranay Jaiswal's user avatar
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 ...
Oleksandr Berehovskyi's user avatar
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 ...
Eric's user avatar
  • 54.3k
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 ...
Adrian Larson's user avatar
  • 151k
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 ...
Adrian Larson's user avatar
  • 151k
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 ...
David Reed's user avatar
  • 93.4k
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....
Daniel Ballinger's user avatar
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 ...
Ilya Lepesh's user avatar
  • 4,135
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 ...
RSG's user avatar
  • 412
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 ...
Tushar Sharma's user avatar
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 ...
Daniel Ballinger's user avatar
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....
sfdcfox's user avatar
  • 500k
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/...
Mohith Shrivastava's user avatar
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 ...
sfdcfox's user avatar
  • 500k
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 ...
sfdcfox's user avatar
  • 500k
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/') ...
sfdcfox's user avatar
  • 500k
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; ...
rmarq423's user avatar
  • 977
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 ...
sfdcfox's user avatar
  • 500k
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 { ...
Keith C's user avatar
  • 137k
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(); ...
Irene's user avatar
  • 1,851
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 ...
sfdcfox's user avatar
  • 500k
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 ...
Santanu Boral's user avatar

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