Loading
Ongoing maintenance for Salesforce HelpRead More
Feature degradation | Gmail Email delivery failureRead More
Set Up and Maintain Retail Execution
Table of Contents
Select Filters

          No results
          No results
          Here are some search tips

          Check the spelling of your keywords.
          Use more general search terms.
          Select fewer filters to broaden your search.

          Search all of Salesforce Help
          Set Up Remote Calls

          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.

          Note
          Note These APIs are governed by Apex REST API limits.

          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

          1. From Setup, find and select Remote Site Settings.
          2. Click New Remote Site.
          3. In Remote Site Name, enter RemoteAPI.
          4. In Remote Site URL, enter the URL for the remote site. For example, www.examplewebsite.com.
          5. 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.
          6. If needed, enter a description of the site.
          7. 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.

          1. Log in to Salesforce as admin.
          2. From Setup, click Developer Console.
          3. In Developer Console, from the File menu, select New.
          4. Click Apex Class.
          5. In the class name, enter RemoteAPI and then click OK.
          6. 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.

          1. Log in to Salesforce as admin.
          2. From Setup, find and select Permission Sets in the Quick Find box, then click Permission Sets.
          3. In Users, go to Permission Sets and select CGCloud Sales User or CGCloud Retail Sales User.
          4. On the permission set page, under Apps, select Apex Class Permissions.
          5. Edit Apex Class Access and add <namespace>.RemoteAPI to Enabled Apex Classes.
          6. 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.

           
          Loading
          Salesforce Help | Article