40

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.getBody(); List<Account> accounts = (List<Account>) JSON.deserialize(s, List<Account>.class);


31

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 that it is then impossible to change the format of the data (because of managed package version compatibility constraints) as the OP mentions, but it also ...


19

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 construct REST APIs for this purpose which the External Systems can utilize to send data to Salesforce. Platform Events are more targeted towards a Pub/Sub model, ...


18

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't need to handle 401 UNAUTHORIZED as if the request fails authentication, your code will never even be executed. However, you typically will want to handle ...


16

You will have to set up your own RestResponse and RestRequest object. RestRequest req = new RestRequest(); RestResponse res = new RestResponse(); req.requestURI = 'https://na11.salesforce.com'; // sample Endpoint req.httpMethod = 'GET'; RestContext.request = req; RestContext.response = res; TestService.doGet(); Look at ...


13

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 CREATED 202 ACCEPTED 204 NO_CONTENT 206 PARTIAL_CONTENT 300 MULTIPLE_CHOICES 301 MOVED_PERMANENTLY 302 FOUND 304 NOT_MODIFIED 400 BAD_REQUEST 401 UNAUTHORIZED 403 ...


13

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 { // Simple echo callout class // Returns whatever response we tell it to when asked class EchoHttpMock implements HttpCalloutMock { ...


12

Below is a pattern I use to vary the status code returned. It only maps two categories of exceptions but if you need to you can add more. Note that only status codes from this list can be returned - you can't return other status codes. By catching Exception it handles most unplanned errors (but can't catch governor limit exceptions), and the purpose of the ...


12

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. Salesforce currently supports version 20 (the Winter 11 API) through 39 (the Spring 17 API). If you build an application today, using version 39, it is ...


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 ...


11

It's a bit hacky, but you could remove the attributes by serialising and deserialising the SObjects to Maps, like this example: Account acc = [Select Id, Name, (Select Id, Name From Contacts) From Account LIMIT 1]; Map<String,Object> accMap = (Map<String,Object>)JSON.deserializeUntyped(JSON.serialize(acc)); removeAttributes(accMap); System....


11

Historically the ability to expose APIs as publicly accessible via sites wasn't very well known, which might have lead to a lot of REST-like visualforce pages by those simply ignorant of the neat feature hidden in sites. Literacy has risen since then, and you can find examples of both, but if you see a lopsided number of historical posts that might well ...


10

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


10

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 invocation originated. In addition, if you use an authenticated REST API, rather than one based on guest user access, you can access detail of the User via the ...


9

Support have come back with: confirmed with R&D that this is not a BUG rather a security update that is introduced in Winter'15 release and advise: affected customers will need to adjust their integration's to not rely on a guest session ID


9

I built a similar service some time ago, and made some similar verifications and tests, I can provide some answers as follows: Any request for 'Your Domain" will count as a page view, see docs You can test the service from runscope (or similar), to get real request times. For example, I have a similar service that performs a SOQL & DML to a single ...


9

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 set up a profile that does not have access to the standard APIs, but gives you access to Apex REST Services. The user will also need access to the apex class ...


8

While it's not clear why that doesn't already work, to get your code out the door, my suggestion is to build your own REST dispatching service. The following pseudo code implementation works as followed: Register for all REST requests for a particular url (e.g. /teams/*) Register different controllers (which implement the interface Dispatchable) In case the ...


8

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 suggestible to test the HTTP url from any on the REST applications like POSTMAN before making a decision in salesforce.


8

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 example Account record can be created as follows If you want to update account you need to pass Account id in url and select PATCH as method type /services/data/...


8

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 DML operations, so there is nothing to rollback on. If the code once called EventCreationhelper there would have been some functional value to using the manual ...


8

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 sObject with attributes, or specify exact class type: string body = '{"account":{"name":"test"}}'; Account acc = (Account)JSON.deserialize(body, Account.class); ...


8

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, either for a client calling your code, or sending data to a server, use the generator. If you're receiving data from an outside source, either from a client or ...


8

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: Suicidal Scheduling While we’re on the topic of chaining, I’d like to describe another disturbing trend, one that I call “suicidal scheduling”. Suicidal scheduling ...


8

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 read-only while caching its value (a lazy-loading pattern), you can synthesize a private setter: get { // ... } private set; That will allow your class ...


7

You can design your own interface using simple Apex classes. So to allow this JSON to be posted: [ {"query": "SELECT ...", "externalId": "65202639238"}, {"query": "SELECT ...", "externalId": "652054239"} ] you just need a class with matching field names and to make the method signature accept an array of these classes: @RestResource(urlMapping='/...


7

The { starts an object and the [ starts an array. It is convenient to deserialise into inner classes (because the class field names must match the JSON names) and then transfer from those into the SObjects: public class Item { public String sName; public String sRating; public String sContact; } @HttpPost global static String createMerchandise(...


7

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 suggest to keep only one class and do all future operations in a single future class


7

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 your questions: Platform Event Allocations Maximum number of event notifications published per hour Performance and Unlimited Editions 100,000 Enterprise ...


7

I think endpoint URL should be: https://ap6.salesforce.com/services/data/v43.0/composite/sobjects?ids=00P0K000016YWusUAG,00P0K000016YWutUAG


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