Salesforce Superbadge: Configuring External and Named Credentials for API Callouts
HTML-код
- Опубликовано: 8 сен 2024
- In this video,
I'll guide you through the process of setting up external credentials and named credentials in Salesforce, focusing on configuring authentication and making secure callouts to an external API, specifically for the Research Guardian integration.
Topics Covered:
Overview of the use case and business requirements for Max Environmental Science Institute (MESI)
Step-by-step guide to configuring external credentials
1. Setting up named credentials in Salesforce
2. Handling custom authentication headers
3. Writing Apex code for making secure API callouts
4. Debugging common issues like unauthorised headers
Whether you're working on a Salesforce superbadge or looking to enhance your Salesforce integration skills, this tutorial will provide you with the essential steps and tips to successfully configure and manage external and named credentials for secure API integrations.
Code :
public with sharing class ResearchServiceController {
public static Integer processEquipmentsRequest() {
HttpRequest req = new HttpRequest();
req.setEndpoint('callout:Research_Guardian/equipments');
req.setMethod('GET');
HttpResponse response = new Http().send(req);
if (response.getStatusCode() == 200) {
String responseBody = response.getBody();
System.debug('Available Equipments: ' + responseBody);
} else {
System.debug('Callout failed with status code: ' + response.getStatusCode());
}
return response.getStatusCode();
}
}
Connect with Me:
Instagram: ankitkpunjabi
LinkedIn: / ankitkumar007
Hashtags:
#Salesforce #Superbadge #NamedCredentials #ExternalCredentials #APIIntegration #ResearchGuardian #SalesforceDeveloper #MuleSoft #Apex
Challenge Not yet complete... here's what's wrong:
We can't find the appropriate access to the authentication tokens.
Ops bad - In video expressions are wrong in custom header
{!$Credential.Secure_Research.client_id}
{!$Credential.Secure_Research.client_secret}
in video expression are encode in quotes like '{!$Credential.Secure_Research.client_secret}' which is wrong. Please update your custom header and try.
Bro just go to permission set name ExtCred - MuleSoft in this object setings serach User External Credentials and give read,edit,create and after that save and go ExtCred - MuleSoft permission set in that below of obeject sents we can searchfor "External Credential Principal Access" in that select"Secure_Research - Infra Collection" then challange will be completed
please give a try adding the External Named Credential that you created(Secure_Research - Infra Collection) to the Permission set(ExtCred - MuleSoft) also .In the permission set , under this option 'External Credential Principal Access'
hey thanks for the challenge one can you please explain me challenge 2?
@@umrakhan143 sure whats the doubt?
@@AnkitKPunjabi stuck 2nd challenge is this issue is that apex class is not successful
Challenge Not yet complete... here's what's wrong:
We can't find that authentication credentials can dynamically adapt to new credentials when rotated for the 'Secure Research' external credential.
Hi @ankitKPunjabi I am following all the steps and creating permission set, public group, adding that group to 2 users everything but still I am now able to see that permission set and public group in principle access and due to this I am getting below error "Challenge Not yet complete... here's what's wrong:
We can't find the appropriate access to the External Credential Principals." . can you help me in this?
@@ashokkumarsharma5760 check external object read access and in permission set > external credential you need add your new external credential
Done everything but still getting below error
Bro just go to permission set name ExtCred - MuleSoft in this object setings serach User External Credentials and give read,edit,create and after that save and go ExtCred - MuleSoft permission set in that below of obeject sents we can searchfor "External Credential Principal Access" in that select"Secure_Research - Infra Collection" then challange will be completed
I am getting 401 unauthorised error. Could you please help here
@@rangurajeevkumar1694 makes sure you have assigned external cred to your permission set
@@AnkitKPunjabi The ResearchServiceController class doesn't make a successful callout.
Finally I have done it.
Upload platform Events superbadge unit also... That helps
Currently working on that will be uploading shortly
@@AnkitKPunjabi Thank you Bro
Getting this error :
We can’t find the appropriate access to the external credentials principals
@@jatindersingh8342 you need to make sure your external credential expression is correct in custom header section
Challenge Not yet complete... here's what's wrong:
The ResearchServiceController class doesn't make a successful callout. I am getting this error
can you verify you external credential setting? expression should be like !$Credential.Secure_Research.client_id}
{!$Credential.Secure_Research.client_secret} - in video it's bit wrong
@@AnkitKPunjabi Yes I verified it's
client_id
{!$Credential.Secure_Research.client_id}
client_secret
{!$Credential.Secure_Research.client_secret}
Still it is not working for me, receiving same error
Yeah I verified the external credentials settings and it is
client_id
{!$Credential.Secure_Research.client_id}
client_secret
{!$Credential.Secure_Research.client_secret}
unfortunately still it is not working
@@AnkitKPunjabi I verified still it is showing same error
external credential setting is as below
client_id
{!$Credential.Secure_Research.client_id}
client_secret
{!$Credential.Secure_Research.client_secret}
Challenge Not yet complete... here's what's wrong:
We can't find that authentication credentials can dynamically adapt to new credentials when rotated for the 'Secure Research' external credential.
@@appleguatno6407 see that external credential you adding correctly
please give a try adding the External Named Credential that you created(Secure_Research - Infra Collection) to the Permission set(ExtCred - MuleSoft) also .In the permission set , under this option 'External Credential Principal Access'
@@mohanvadla4341 did that and still same fail
ankit skipped a step from somewhere
use these
{!$Credential.Secure_Research.client_id} and
{!$Credential.Secure_Research.client_secret} instead fo hard ones on the headers.