30

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


23

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);


16

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


13

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


12

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

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

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


11

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


11

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


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

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


9

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


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

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

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


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

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


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

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


6

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='/...


6

As it is custom Apex code, instead of directly returning the SObject, return a simple "bean" class that just has an Id and Name property with the values copied from the SObject: public class Bean { public Id Id; public String Name; Bean(SObject sob) { this.Id = sob.Id; this.Name = (String) sob.get('Name'); } } PS Based on the ...


6

Salesforce backed out this across-the-board change and made it a versioned changed. API Version 31 and earlier will continue to return the session ID from UserInfo.getSessionId() when in the Sites guest user context. Your VF Page and Apex Controller must be Version 31 or earlier. The patch hit the Winter '15 sandboxes last night (Sept 30) and will hit the ...


6

Updated: As of the Summer '16 release CORS is available for Apex REST Classes. This is described in Use CORS to Access Salesforce Resources from Web Browsers. These Salesforce technologies support CORS. Analytics REST API Bulk API Chatter REST API Salesforce IoT REST API Lightning Out REST API User Interface API Apex ...


6

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.


6

Once you annotate your class with @RestResource salesforce takes care of setting status and header. Even if you set return type as void your client requesting resource will still see the status code of 200 and if your apex fails your client will see failure with 500 status code or 400. Whatever you return only defines body of the response not header. Use ...


6

You can use standard REST API as showed by above answer .Also i would like to point out mistake you are doing in the custom REST API The JSON parameters that you send should match the parmeters of the @HTTP POST function of apex .Hence your proper JSON as per function you have written would be as below { "nm" : "Sansui Corp", "Descrip" : "Electronics ...


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