Set Up Remote Calls
The Consumer Goods offline mobile app supports remote calls over REST API. This integration of the CG Cloud offline mobile app with Salesforce and external endpoints configured via Salesforce provides sales reps access to real-time data. RemoteCalls API supports only JSON format response. Customizers can use this capability to implement data integration projects specific to their business requirements.
Required Editions
| Available in: Enterprise and Unlimited Editions that have Consumer Goods Cloud enabled |
| User Permissions Needed | |
|---|---|
| To set up remote calls over REST API | CGCloud Business Admin OR CGCloud Retail Business Admin |
To enable remote calls from the app, configure the RemoteCalls.remoteApiCallAsync API in Visual Studio (VS) Code based Modeler. You can
define the flow of how the app consumes the data collected from the endpoint and renders it on
the UI by configuring business logic contracts in your customization project. The framework
triggers the remote API call only when the CG Cloud offline mobile app is
online.
RemoteCalls API supports only JSON format response.
Add and authorize a remote site with the HTTP base
URL of the Apex endpoint in Salesforce. Configure access permissions and then implement and test
the endpoint to ensure that it’s secure and functions correctly. Configure business logic
contracts in your customization project in VS Code based Modeler and define the remoteApiCallAsync API with the request payload.
Authorize External Endpoint URL
- From Setup, find and select Remote Site Settings.
- Click New Remote Site.
- In Remote Site Name, enter RemoteAPI.
- In Remote Site URL, enter the URL for the remote site. For example, www.examplewebsite.com.
-
To allow access to the remote site irrespective of whether the user’s connection is over
HTTP or HTTPS, select the Disable Protocol Security checkbox. When
selected, Salesforce can pass data from an HTTPS session to an HTTP session, and vice
versa.
Select this checkbox only after you review all security implications.
- If needed, enter a description of the site.
- Click Save to complete registration, or click Save & New to save your work and register another site.
Create an Endpoint
Consumer Goods Cloud offline mobile app supports remote calls only with Salesforce endpoints (Apex-based REST API calls). All standard Apex governor limits apply to Apex REST classes.
- Log in to Salesforce as admin.
- From Setup, click Developer Console.
- In Developer Console, from the File menu, select New.
- Click Apex Class.
- In the class name, enter RemoteAPI and then click OK.
-
Implement your custom business logic in your VS Code based Modeler workspace to invoke
REST API in this class.
Here’s a sample of GET and POST requests:
@RestResource(urlMapping='/remoteapi/*') global with sharing class RemoteAPI { @HttpGet global static void getData() { // new HTTP request to external end point Http http = new Http(); HttpRequest request = new HttpRequest(); request.setEndpoint('https://www.examplewebsite.com'); request.setMethod('GET'); HttpResponse responseFromRemoteSite = http.send(request); String data = responseFromRemoteSite.getBody(); System.debug(data); // Prepare response RestResponse res = RestContext.response; res.addHeader('Content-Type', 'application/json'); res.responseBody = Blob.valueOf(data); res.statusCode = responseFromRemoteSite.getStatusCode(); } @HttpPost global static void postData() { String requestBody = RestContext.request.requestBody.toString(); // new HTTP request to external end point Http http = new Http(); HttpRequest request = new HttpRequest(); request.setEndpoint('https://www.examplewebsite.com'); request.setMethod('POST'); request.setHeader('Content-Type', 'application/json'); request.setBody(requestBody); HttpResponse responseFromRemoteSite = http.send(request); String data = responseFromRemoteSite.getBody(); System.debug(data); RestResponse res = RestContext.response; res.addHeader('Content-Type', 'application/json'); res.responseBody = Blob.valueOf(data); } }
Configure Remote API Access Permission
To access the new API from VS Code based Modeler, grant sales reps access to the newly created remote API.
- Log in to Salesforce as admin.
- From Setup, find and select Permission Sets in the Quick Find box, then click Permission Sets.
- In Users, go to Permission Sets and select CGCloud Sales User or CGCloud Retail Sales User.
- On the permission set page, under Apps, select Apex Class Permissions.
- Edit Apex Class Access and add <namespace>.RemoteAPI to Enabled Apex Classes.
- Save your changes.
Post Configuration Tasks
Test the endpoints by using an API testing tool. On successful testing, define the
remoteApiCallAsync API in your customization
project.
The definition must contain all mandatory parameters for GET and POST. Here are a few
remoteApiCallAsync sample definitions.
Sample GET requests:
-
RemoteCalls.remoteCallApiAsync({path:'/remoteapi'}) -
RemoteCalls.remoteCallApiAsync({ path:'/remoteapi', method: "GET" })
Sample POST request:
RemoteCalls.remoteCallApiAsync({ path:'/remoteapi', method: "POST", data: {}
})
If your endpoint is deployed in a namespace, include the namespace in the business logic
URL. For example, if the deployed REST endpoint URL is
<instanceURL>/services/apexrest/cgcloud/remoteapi, configure the
business logic URL to call remoteApiCallAsync with
/cgcloud/remoteapi as path parameter.

