Welcome to the 3rd tutorial in Simplifying the Callouts in Salesforce Tutorial Series. In this tutorial we're going to connect two salesforce orgs thereby learning the concept of Named Credentials, Authentication Provider and HTTPCalloutFramework in detail. As this is a Video-Only tutorial series. I am giving you a brief of what we've done in this tutorial below, and you can have a detailed look in the related video. So, let's begin.
As we're going to connect two orgs that means, we'll be fetching some data from one org to another. Let's call the org from which we're going to fetch data as the Source Org and let's call the org which is pulling the data from source org as the Destination Org.
Connected App in Source Org
Notice that we have selected two OAuth scopes here:-
- Access and manage your data (api) :- Used to query data from Salesforce
- Perform requests on your behalf at any time (refresh_token, offline_access) :- Used to maintain the refresh token which will be used by authentication provider in order to get new access token automatically when refresh token expire.
Authentication Provider in Destination Org
- Provider type is Salesforce as we're going to connect to a Salesforce Org.
- Consumer Key and Consumer Secret are copied and pasted from our connected app which is made in another salesforce org as shown above.
- Callback URL is automatically generated when you save the record of your authentication provider. We need to copy and paste this callback url in our connected app which was created in the source org and update that connected app (You can see above that our connected app is having the same Callback URL which is given by our authentication provider). I've updated it later.
Named Credential in Destination Org
HTTPCalloutFramework in Destination Org
Fetching Data from Source Salesforce Org to Destination Salesforce Org
Note:- Here we can easily add any dynamic query because it's handled in the URL parameters. But in case you need to add any dynamic value in the request body let's say, I would recommend to have the format in the HTTPCalloutConfiguration record and use string replace and getters/setters to update the request body before callout.
If you want to have a detailed look, you can watch the video below:-
That's all for this tutorial. In the next tutorial, we'll have a look at how we can create a test class to manage multiple callouts in single transaction. Our test class will be having 100% code coverage and that too without creating a mock class. So, stay tuned.
Happy Trailblazing..!!
good work!! very well written!! keep it up friend
ReplyDelete