Newer Version Available
Get an Authentication URL
This example calls getOAuthCredentialAuthUrl(requestBody) to retrieve the URL that a user must
visit to begin an authentication flow, ultimately returning authentication tokens to Salesforce.
Accepts input parameters representing a specific external credential and, optionally, a named
principal. Use this method as part of building a customized or branded user interface to help
users initiate authentication.
1ConnectApi.OAuthCredentialAuthUrlInput input = new ConnectApi.OAuthCredentialAuthUrlInput();
2
3input.externalCredential = 'MyExternalCredentialDeveloperName';
4input.principalType = ConnectApi.CredentialPrincipalType.PerUserPrincipal;
5input.principalName = 'MyPrincipal'; // Only required when principalType = NamedPrincipal
6
7ConnectApi.OAuthCredentialAuthUrl output = ConnectApi.NamedCredentials.getOAuthCredentialAuthUrl(input);
8
9String authenticationUrl = output.authenticationUrl; // Redirect users to this URL to authenticate in the browser