Episode 4. Salesforce to Salesforce Integration using — Direct Connection
The idea of this integration is just to highlight key items one needs to make direct connection between one Salesforce org to another using basic approach.
Please note: No recomendation or emphasis on whether you should always use this approach when it comes connecting orgs. There are various others multiple options & solutions one needs to carefully assess keeping in mind considering other hidden factors (system landscape, Orschestration, Volume & scalability)
Use case: There are 2 Salesforce Org, lets call them 1) Master SFDC Org, 2) Child SFDC Org. where in we want to access the data cross clouds, meaning user sitting in Org A(child) should be able to access the data in another SF Org B (Master Org.) or vice versa.
let’s get started — take a note of the ingredients on a paper -
Connected app: You need Connected app in master SFDC Org. | Purpose: This acts as a gateway (mediator) whose job is go to SF authorization server & ask for authorization for your external App (i.e. child Org) based on your user’s behalf in Master Org)
Authorization provider in Child SFDC Org.: | Purpose: to hold all the authorization details (your consumer key , secret and endpoint endpoints) see it like a packet
Named Crdentials in Child SFDC Org.: | Purpose: takes the JOB of handling authentication for your API callouts (basically this offloads the storage of credentials & authentication decalaratively) & gets you authenticated in Master Org. to access any resource.,, resource mean anything that exists in master org and can be queried / accessed)
- Also NC: In here we primarily specifies a callout endpoint and its required authentication parameters which comes from Auth provider (basically in here you link your callout endpoint & your auth provider setup above)
Example of this is : lets see this to understand what i mean -
AS IS (traditional way) Vs. Modern way with Named Credentials
Remote Site Setting: Any address or endypoint that you would like to callout / invoke from Salesforce
Apex Callout Framwork (optional): this is a nice utility to always keep one in your Org. while testing or implmenting any callouts from Salesforce-
- There is 1 nice & easy to understand framework buit by a “Salesforce Hero” named Rahul, which you should take a look install in your org. to make your life easy https://github.com/rahulmalhotra/HTTPCalloutFramework
On a side note: C A N R A (makes sense, atleast not to me haha!)
Follow the snapshots below in the order as explained below,
1.Connected App → 2. Authorization provider → 3. Named Credential(for authentication) → 4. Remote Site setting for your master org in child org. →5. lastly install the apex callout framework
- Jump to your master SFDC Org. Create Connected app → Copy the Consumer Key and Secret (also in calback url for now just add anything)
- Jump to Child Org: Create Auth provider → paste consumer key; secret (copied from above) and default scope as api refresh_token, leave rest empty
- Copy the callback Url from below and now for a second → navigate to your master Org. and update your newly created connected app with the copied calback url in the Callback url field (this must be same) 2 snapshots below:
- Create a named Credential in the Child Org. select all fields as shown below , remmber to check highligted one. this will take you to your master SFDC org for authentication, notice the url (login with your master SFDC crdentials)
- On save you will be redirected to master SFDC Org. enter username , password and click allow
- At this point, you will be redirected back to your child Org. again and as you could see the status below shows authenticated
- Before making a callout, add the remote site url (master SFDC Org url) take it from your user icon in lightining or switch to classic and copy the url until .com
- Last Step is to intsall Apex callout framework, & onc done just follow the steps lined out in th github repo. once ready, open Developer console. → execute anonymous → this is the key:
HttpCalloutService service = new HTTPCalloutService(‘Get_Master_Org’);
And Done, you will see the debug log — all the accounts extracted from master SFDC Org. you can create a lightning component Or visualforce to show the data on screen for the internal users and and can use the same api framework to make changs and Submit to your master Org.
keep reading and learning!
Thanks — Mohit