Hi ,
So you have created a Rest class and exposed it. At this stage you know how you can test this using Workbench.
Ex: If your class name is : getAccountDetails which is expecting 2 parameters.
then in the workbench, you will go to rest Explorer and select Get/Post based on the requirement and paste the URL something similar to this.
/services/apexrest/CKDomain/getAccountDetails?Param1=1100055515&Param2=13706195
And BAM!!!! Everything looks fine.
But in real time scenarios, you might want to give this endpoint URL to some other system (Say SAP/Oracle) and you want to test from your end before informing them about the endpoint URL. So how can we achieve this.
There are many ways to test this and I prefer using Postman app for this. Install Postman from here.
Now , In order to successfully receive a Rest call out from Other system to Salesforce , there are multiple auth techniques. I would like to use the most commonly used auth technique - OAuth 2.0
As per my knowledge, a Simple OAuth 2.0 authentication needs 4 important parameters and they are,
1.User Name
2.Password
3.Client Secrete
4.Client ID
NOTE: If you are trying make a webservice callout another salesforce instance then please follow this post
How do we get the Client Secret and Client ID ? To get this unique gate pass informations we need to create a connected app.
Go to Setting >>App setup >> Apps >>Scrolldown to bottom >>Connected Apps >>Click new and fill in the details as shown in the below diagram.
Now, it may take a while for salesforce to establish this connect app. After 2- 10 mins you can go to the connected app and you will see something similar in the below image.
Now we have Consumer Key /Client ID and Client Secrete.
Let go to Postman app Now.
After launching the app you can click on New tab and select 'POST'. In the same click on the Params button. In the Authorization sub tab select OAuth 2.0
Now you can see something like below image.
Now in the Postman URL section you we need to enter the endpoint URL which other systems would be hitting in order to get into salesforce system.
Step 1. First one should make a call out to get the access_token
Step 2. Make a actual callout for getting the desired data with access_token obtained in the previous step.
Step 1 :
In Postman's URL section enter :
https://login.salesforce.com/services/oauth2/token?grant_type=password&client_id=***Consumer Key from connected App **&client_secret=**Client Secrete ID from connected App**&username=chanz707@gmail.com&passwor=**your org password+securityToken**
If you have IP Restrictions ON, then no need of providing the Security Token info along with the password.
After you enter all the detail correctly the request would look similar to below image.
Now you are a authorized third party system.
Step 2:
Once you have the access_token, now its time to hit the actual end point to get the desired data with obtained access_token. Another important parameter to be noticed is instance_url . Till now you used login.salesforce.com / test.salesforce.com .
Now the next call out should include the instance_url and access_token from previous step.
Next call out will look like below image with 2 header information as shown.
Authorization : Bearer + access_token
content_type : application/json
Sample Endpoint URL :
https://***instance_url***/services/apexrest/getProductDetailsSmartSearch?searchString=VNXe&userBadgeId=1100055515
Thats All, You have tested yourself that third party system can access the exposed data using Rest endpoint URL
So you have created a Rest class and exposed it. At this stage you know how you can test this using Workbench.
Ex: If your class name is : getAccountDetails which is expecting 2 parameters.
then in the workbench, you will go to rest Explorer and select Get/Post based on the requirement and paste the URL something similar to this.
/services/apexrest/CKDomain/getAccountDetails?Param1=1100055515&Param2=13706195
And BAM!!!! Everything looks fine.
But in real time scenarios, you might want to give this endpoint URL to some other system (Say SAP/Oracle) and you want to test from your end before informing them about the endpoint URL. So how can we achieve this.
There are many ways to test this and I prefer using Postman app for this. Install Postman from here.
Now , In order to successfully receive a Rest call out from Other system to Salesforce , there are multiple auth techniques. I would like to use the most commonly used auth technique - OAuth 2.0
As per my knowledge, a Simple OAuth 2.0 authentication needs 4 important parameters and they are,
1.User Name
2.Password
3.Client Secrete
4.Client ID
NOTE: If you are trying make a webservice callout another salesforce instance then please follow this post
How do we get the Client Secret and Client ID ? To get this unique gate pass informations we need to create a connected app.
Go to Setting >>App setup >> Apps >>Scrolldown to bottom >>Connected Apps >>Click new and fill in the details as shown in the below diagram.
Now, it may take a while for salesforce to establish this connect app. After 2- 10 mins you can go to the connected app and you will see something similar in the below image.
Let go to Postman app Now.
After launching the app you can click on New tab and select 'POST'. In the same click on the Params button. In the Authorization sub tab select OAuth 2.0
Now you can see something like below image.
Now in the Postman URL section you we need to enter the endpoint URL which other systems would be hitting in order to get into salesforce system.
Step 1. First one should make a call out to get the access_token
Step 2. Make a actual callout for getting the desired data with access_token obtained in the previous step.
Step 1 :
In Postman's URL section enter :
https://login.salesforce.com/services/oauth2/token?grant_type=password&client_id=***Consumer Key from connected App **&client_secret=**Client Secrete ID from connected App**&username=chanz707@gmail.com&passwor=**your org password+securityToken**
If you have IP Restrictions ON, then no need of providing the Security Token info along with the password.
After you enter all the detail correctly the request would look similar to below image.
Now you are a authorized third party system.
Step 2:
Once you have the access_token, now its time to hit the actual end point to get the desired data with obtained access_token. Another important parameter to be noticed is instance_url . Till now you used login.salesforce.com / test.salesforce.com .
Now the next call out should include the instance_url and access_token from previous step.
Next call out will look like below image with 2 header information as shown.
Authorization : Bearer + access_token
content_type : application/json
Sample Endpoint URL :
https://***instance_url***/services/apexrest/getProductDetailsSmartSearch?searchString=VNXe&userBadgeId=1100055515
Thats All, You have tested yourself that third party system can access the exposed data using Rest endpoint URL
Very useful information, if you are Looking for software courses?
ReplyDeleteCloud Computing Courses in Chennai
Hadoop Training in Chennai
Digital Marketing Course in Chennai
Selenium Training in Chennai
JAVA Training in Chennai
German Classes in chennai
JAVA Course in Chennai
The titanium Flask - Titanium Glass - TITNIA AVEMENT - TITNIA AVEMENT
ReplyDeleteThe titanium Flask. Description: This ceramic vs titanium curling iron item stainless steel vs titanium apple watch is used for an titanium stronger than steel alloy of titanium cobalt vs titanium drill bits oxide. Made in Germany. thinkpad x1 titanium