Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.
RestClient Class
As its name implies, the RestClient class is an Android app’s liaison to the Salesforce REST API.
You don’t explicitly create new instances of the RestClient class. Instead, you use the ClientManager factory class to obtain a RestClient instance. Once you get the RestClient instance, you can use it to send REST API calls to Salesforce. The method you call depends on whether you’re calling from a UI context. See ClientManager Class.
Use the following RestClient methods to send REST requests:
- sendAsync()—Call this method if you obtained your RestClient instance by calling ClientManager.getRestClient().
- sendSync()—Call this method if you obtained your RestClient instance by calling ClientManager.peekRestClient().
sendSync() Method
You can choose from three overloads of RestClient.sendSync(), depending on the degree of information you can provide for the request.
sendAsync() Method
The RestClient.sendAsync() method wraps your RestRequest object in a new instance of the OkHttpClient Call class. It then adds the Call object to the request queue and returns that object.
Tocancel a request while it’s pending, call cancel() on the Call object. To access the underlying request queue object, use the OkHttpClient class. See examples at Managing the Request Queue.