36

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 to do with it (Profiles will need to be pre-authorized with the connected app, or users will need to approve the connected app through some other OAuth flow before you can ...


12

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 like @RestResource(urlMapping='/Revenues/*) @HttpGet global static List<Case> getOpenCases() { String accountId = RestContext.request.params.get('...


12

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 parameter ,so you will need to select post and then the JSON input is { "username" : "test" } The response will tell you the JSON structure .Also just by ...


10

I have solved the issue. Solution: If you have namespace defined in salesforce you need to define it with /services/apexrest/namespace/lead


9

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 way your post method apex will be called and SF will not try to parse it. Then you can parse it manually and make your magic work. public class RequestWrapper{...


6

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. So, in your case you can used your Custom Domain but not the login URL.


5

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 method returns an empty set of search results when the test method executes. If you do not want the query to return an empty list of results, you can use the Test....


5

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 class: system.debug(JSON.serializePretty(BP_Routes.BP_Routes('APPROPRIATEUSERNAMEHERE'))); And the other answers work as well, this is just pretty easy to do ...


5

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 global static void doPost() { insertLead(RestContext.request.params.get('id')); } @future public static void insertLead(String id) ...


5

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 can change that rule. The source code of that rule is present here: https://github.com/pmd/pmd/blob/master/pmd-apex/src/main/java/net/sourceforge/pmd/lang/...


5

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 your class can parse and utilize the parameter value - an Account Id or External Id, for example. Interstitial wildcards do the same thing. /Accounts/*/Contacts ...


4

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 will give HTTP 500 and: [ { "errorCode": "APEX_ERROR", "message": "System.DmlException: Insert failed. First exception on row 0; first error: ...


4

Sadly, this means that you'll need to use either a JSONParser or a generic Object that you can get from JSON.deserializeUntyped. In summary, that means you'll ultimately need to do a bit more heavy lifting than if there were no reserved keywords. I prefer to use JSON.deserializeUntyped, personally, but this means you'll need to know what kind of data is ...


4

That tells you the URL path. So when you want to hit your service you would use: /services/apexrest/CompanyData/


4

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 RepsonseWrapper structure as below - global Class ResponseWrapper{ public String statusCode; public Datetime responseOut; public Integer recordCount; ...


4

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.GfE0C9xyWMrTzONlj2GZ0ow6VK'; string clientSecret = '1234567896475551576'; // @ will be encoded to %40 string username = EncodingUtil.urlEncode('john@example.com', 'UTF-8'); ...


4

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 this in your sandbox or you can sign up for pre release org and can check this.


4

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 member variables of the user-defined type, unless the variable is declared as static or transient. Their example is related to deserialization, but the inverse ...


3

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 any point. You could actually write something like this: restRequest.requestURI = 'Hello, there. How are you? I am fine.'; and your test could still pass, ...


3

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/') global class MappedClass { @HttpPost global static void doPost() { } } Invalid (But Previously Compiled) @RestResource(urlMapping='/someUrl/') global class ...


3

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 the Rest Context RestRequest req = new RestRequest(); RestResponse res = new RestResponse(); req.requestURI = '/services/apexrest/Something'; //...


3

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 for additional information, such as /services/apexrest/UpdateCase/500300000012345. You can even use wildcards in the middle of the URL, such as /services/...


3

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; charset=UTF-8 Accept: application/xml


3

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. Several optimizations when you're talking about 10k+ items follow. Pre-Initialize Arrays Using List.add is relatively expensive. You can save that per-item cost ...


2

Unless you are working with the raw content, any parameters that your REST method has Salesforce will automatically attempt to de-serialize from the request body, so you wouldn't need to know the content type in that scenario. If you do want to work with the raw content, then to determine the type you'd need to inspect the request object: RestRequest req = ...


2

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 Rest Explorer input box you just need to change /services/data/... to /services/apexrest/... when trying to access your Custom Apex REST resources. For more ...


2

You can access the params map via static fields like this: Map<String, String> params = RestContext.request.params; String name = params.get('name'); (Remove the getmycall method parameters you presently have in your code.)


2

I received an update from Xero today saying they had deployed a change and it will accept the BrowserId Cookie that is returned by Salesforce so you should be good to go now :)


2

You definitely can't control it from Salesforce's end; Salesforce checks authentication very early in the stack process, before any code you could possibly write could run. Your ideal situation would be to configure the third party system to not do this. Otherwise, you could also use an ESB (Enterprise Server Bus) to strip out the header (at least, any ...


2

With application/json it expects you to provide deserializable parameters to the method. What you should do is make a class that represents what you expect to receive in your post: public class personPost { public String name {get; set;} public String age {get; set;} public personPost(){} } public class personResponse { public Boolean ...


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