While there are many easy point and click methods of accessing Salesforce Data Cloud data, sometimes it may be necessary to query Data Cloud remotely using Data Cloud Connect APIs.
In this article I have shared working examples of LWC and APEX that I wrote to retrieve and display Data Cloud data in a remote org.
This article would not explain the foundational concepts of Apex,LWC, Connected Apps or Named Credentials. There are excellent videos and articles about these topics on the internet including of course, the Salesforce Help & Training documentation.
Following is a summary of steps and my code.
Authenticating to Salesforce Data Cloud
In the Data Cloud home org, you need to create a connected app, create permission set, assign permission set to Connected app, assign default data space to the permission set. Ref: https://trailhead.salesforce.com/content/learn/projects/build-a-connected-app-for-api-integration/create-a-connected-app
In the remote org that will make an API call to Data Cloud, you create Named Credentials, External Credentials and Auth Provider: Ref: https://help.salesforce.com/s/articleView?id=sf.nc_example_oauth_github.htm&type=5
You may also want to configure Remote Site Settings: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_callouts_remote_site_settings.htm
Writing Apex & LWC Code
Install Code Builder in the remote org (not the Data Cloud home org): https://developer.salesforce.com/docs/platform/code-builder/guide/codebuilder-overview.html
Following are the different pieces of code
For simplicity, I have hard coded the where clause. In my apex callout from org2 (remote) to org1 (DataCloud) I am fetching all the individual DMO records corresponding who have first name as āCā (select ssot__LastName__c from ssot__Individual__dlm where ssot__FirstName__c=\’C\’ā)
Now we can create the LWC files.
LWC: getdc01.html: https://github.com/lightningexperience/Data-Cloud-API-Integration/blob/main/getdc01.html
LWC: getdc01.js: https://github.com/lightningexperience/Data-Cloud-API-Integration/blob/main/getdc01.js
LWC: getdc01.js-meta.xml: https://github.com/lightningexperience/Data-Cloud-API-Integration/blob/main/getdc01.js-meta.xml
In another post I have taken a different approach to making API callout: A Working Example of Apex Callout Using Invocable Apex Method and Salesforce Flow to Retrieve Data from Salesforce Data Cloud API
Caution: This example is for demo purpose only. Please use the official Salesforce documentation for your project
2,587 total views, 2 today