Skip to main content
22 votes
Accepted

Apex Framework / library for consuming REST services

The ffhttp library should do the trick: https://github.com/financialforcedev/ffhttp-core It includes error handling, redirections, building header fields, oauth, mime attachments and more. EDIT - ...
frup42's user avatar
  • 414
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
  • 10.2k
18 votes
Accepted

What is the longest URI that Salesforce will accept through the REST API?

+edit 2020-10-25: Looks like there's some concrete documentation as of API v49.0 (Summer '20). The documented limit is 16,384 bytes. The recommendation is to limit the URI to 2000 bytes, and headers ...
Derek F's user avatar
  • 62.7k
17 votes
Accepted

Malformed JSON: Expected '{' at the beginning of object?

Try this ;) List<permissionDataWrapper> delegationMap = (List<permissionDataWrapper>)JSON.deserialize(RestContext.request.requestBody.toString(), List<permissionDataWrapper>.class);...
itzmukeshy7's user avatar
  • 3,170
15 votes
Accepted

What is the default timeout for httpRequest?

From documentation: The default timeout is 10 seconds. A custom timeout can be defined for each callout. The minimum is 1 millisecond and the maximum is 120,000 milliseconds. The maximum ...
Reshma's user avatar
  • 4,039
14 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
  • 312
12 votes
Accepted

RemoteAction Vs REST? Which is faster?

@RemoteAction is the fastest you can go without using API calls. If you don't mind using API calls, the AJAX Toolkit is very slightly faster. That said, a well-written RemoteAction can easily run in 1/...
sfdcfox's user avatar
  • 497k
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

converting string to Schema.SObjectField

You could try: String testString = 'Account.example__c'; List<String> splitString = testString.split('\\.'); Schema.SobjectField theField = Schema.getGlobalDescribe().get(splitString[0])....
Nick C's user avatar
  • 6,790
10 votes
Accepted

How to publish/consume bulkified Platform Events

My original answer, while useful is not the full story. After an extended discussion on the Platform Events Success Community with the Product Manager, it turns out as a trigger (or for that matter, ...
cropredy's user avatar
  • 72.1k
9 votes
Accepted

Rest API working well from Postman doesn't work from Salesforce

I would use the generate code button in postman, select the cUrl type. Take a look at the headers it generates on the working Postman version (the parameters with the -H) and add them to your apex ...
JimRae's user avatar
  • 5,066
9 votes
Accepted

Handle JSON array from REST call

You have an array of objects, so you should use: List<SalesData> resultList = (list<SalesData>) JSON.deserializeStrict( response.getBody(), List<SalesData>....
sfdcfox's user avatar
  • 497k
9 votes

How to publish/consume bulkified Platform Events

In V42.0, SFDC added a new REST composite collection resource that is bulkified and works with Platform Events! /services/data/v42.0/composite/sobjects { "allOrNone" : false, "records" : [{ ...
cropredy's user avatar
  • 72.1k
9 votes

Lightning: Getting a 401 when calling @AuraEnabled Apex method to do a REST call

The Session Id for Lightning is specifically restricted from most API calls. This means that you need to use a Named Credential to enable access to the APIs. This is outlined in the documentation. By ...
sfdcfox's user avatar
  • 497k
9 votes

How to update a record in a trigger with value from a REST API?

Specific Issues Your method signature is public static void getTicker(String retVal) { but you are passing it Trigger.new, a List<sObject>. The compiler is looking for public static void ...
David Reed's user avatar
  • 93.2k
8 votes
Accepted

Username-Password OAuth Authentication for community users?

In the profile of the user make it as API enabled. I was able to log in using api inside the community using the below soap login call., <Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"...
Pranay Jaiswal's user avatar
7 votes
Accepted

Using HTTP Trace in Salesforce

So, according to OWASP having the TRACE support on your server is generally a bad idea. TRACE: This method simply echoes back to the client whatever string has been sent to the server, and is used ...
Daniel Ballinger's user avatar
7 votes
Accepted

ErrorCode 180008 - Unable to queue Triggered Send request. There are no valid subscribers

Make sure you checked the option Add subscribers to this list under Subscriber Management when creating your triggered send. To verify this option, go to Email Studio > Interactions > Triggered ...
Markus Dang - formerly Slabina's user avatar
7 votes

converting string to Schema.SObjectField

Yo can use Schema.getGlobalDescribe() method to retrieve Map of field of Sobject and then get desired field by name from this Map. Important, that keys for sobject names and sobject field names are ...
Oleksandr Berehovskyi's user avatar
7 votes

How to Query ApexLog raw body?

You don't name a use case, or whether there is a particular place you are integrating this from. But if it was just a matter of, "I need to get a log out and check for some string value in it," these ...
pchittum's user avatar
  • 19.8k
7 votes
Accepted

How to return null for list if we have too many records?

First, you have to create wrapper for response class, so that you can tell is it successful request, or not. Second, you can query 1001 records and if list of queried records is more than 1000, return ...
Oleksandr Berehovskyi's user avatar
6 votes
Accepted

Rest uri using Workbench

If you want to execute creation of Account and Contact all in single call you can use Composite API like below URI /services/data/v38.0/composite/ Request Body { "allOrNone": true, "...
Mohith Shrivastava's user avatar
6 votes

can we query SOSL using REST API?

Yes you can do SOSL query using REST Api. The api would be - /services/data/v37.0/search/?q=SOSL search string The SOSL search string needs to be URL encoded. Here is a link for more details - SOSL ...
Santanu Halder's user avatar
6 votes
Accepted

Custom Auth Provider usage for unattended OAuth flow

You cannot write an initiate method for a Custom Auth Provider without returning a valid PageReference object (i.e. redirect page). Salesforce configuration for Named Credential with a Custom ...
Joe's user avatar
  • 121
6 votes
Accepted

Posting multiple values using Apex Rest callout with POST method

The answer would be if the remote service was able to process it would be to post the object array. [{"name": "mighty moose"},{"name": "dumb moose"}] results in a response of USER_DEBUG|[14]|...
Eric's user avatar
  • 54.2k
6 votes
Accepted

Integration with REST API that is not CRUD

In Salesforce, everything is a CRUD operation. As far as your service is concerned, it needs to support CRUD OData operations. Your application would need to be modified to support CRUD operations. ...
sfdcfox's user avatar
  • 497k
6 votes
Accepted

JSON Parsing of REST response

Don't bother using JSONParser. It's inefficient, and really only meant for porting Java code, as far as I can tell. Since you're only concerned with a few elements, you can just do the following: ...
sfdcfox's user avatar
  • 497k
6 votes
Accepted

Sorting list in replacing in a specific order

This is what the Comparable Interface is for. You'd have your Vision class implement the interface (i.e. global class Vision implements Comparable{...), and then provide an implementation of the ...
Derek F's user avatar
  • 62.7k
6 votes
Accepted

Salesforce REST upsert for externalId cause DUPLICATE_VALUE error

After a month of discussions with Indian support of all tiers, we've got next: Salesforce can't proceed too fast UPSERT queries. If you send two requests with delay about a second or less you'll get ...
KorbenDallas's user avatar
6 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

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