NamedCredentials Class
Create, refresh, get, delete, replace, and update credentials. Create and get external credentials. Create and get named credentials. Create, get, delete, and update external auth identity providers. Get the URL for the OAuth token flow for an external credential.
Managed packages can access only the named credentials and external credentials that are included in or created from the package’s Apex code. If a managed package tries to access non-packaged named credentials and external credentials that a Salesforce admin created in the org, an error occurs.
These methods are for NamedCredentials. All methods are static.
-
Create a credential.
-
createCredential(requestBody, action)
Refresh an OAuth or AWS Roles Anywhere credential.
-
createExternalAuthIdentityProvider(requestBody)
Create an external auth identity provider.
-
createExternalAuthIdentityProviderCredentials(fullName, requestBody)
Create external auth identity provider credentials.
-
createExternalCredential(requestBody)
Create an external credential.
-
createNamedCredential(requestBody)
Create a named credential.
-
deleteCredential(externalCredential, principalName, principalType)
Delete a credential.
-
deleteCredential(externalCredential, principalName, principalType, authenticationParameters)
Delete a credential with authentication parameters.
-
deleteExternalAuthIdentityProvider(developerName)
Delete an external auth identity provider.
-
deleteExternalCredential(developerName)
Delete an external credential.
-
deleteNamedCredential(developerName)
Delete a named credential.
-
getCredential(externalCredential, principalName, principalType)
Get a credential.
-
getExternalAuthIdentityProvider(fullName)
Get an external auth identity provider.
-
getExternalAuthIdentityProviderCredentials(fullName)
Get external auth identity provider credentials.
-
getExternalAuthIdentityProviders()
Get a list of external auth identity providers in the org.
-
getExternalCredential(developerName)
Get an external credential, including the named credentials and principals associated with it and the type and status of each principal.
-
Get external credentials that the user can authenticate to.
-
getNamedCredential(developerName)
Get a named credential.
-
Get a list of named credentials for the org.
-
getOAuthCredentialAuthUrl(requestBody)
Get the URL for the OAuth token flow for an external credential.
-
Update custom credentials.
-
Replace a credential.
-
updateExternalAuthIdentityProvider(developerName, requestBody)
Update an external auth identity provider.
-
updateExternalAuthIdentityProviderCredentials(fullName, requestBody)
Replace external auth identity provider credentials.
-
updateExternalCredential(developerName, requestBody)
Update an external credential.
-
updateNamedCredential(developerName, requestBody)
Update a named credential.
See Also
- Salesforce Help: Named Credentials
- Named Credentials Developer Guide: Get Started with Named Credentials
- Named Credentials Developer Guide: Named Credential API Links
- Apex Developer Guide: Invoking Callouts Using Apex
- Apex Developer Guide: Named Credentials as Callout Endpoints
Create a credential.
56.0
No
public static ConnectApi.Credential createCredential(ConnectApi.CredentialInput requestBody)
- requestBody
Type:
ConnectApi.CredentialInputA
ConnectApi.CredentialInputclass.
Type: ConnectApi.Credential
Refresh an OAuth or AWS Roles Anywhere credential.
58.0
No
public static ConnectApi.Credential createCredential(ConnectApi.CredentialInput requestBody, ConnectApi.CreateCredentialAction action)
requestBody
Type: ConnectApi.CredentialInput
A ConnectApi.CredentialInput class.
action
Type: ConnectApi.CreateCredentialAction
Action to take when creating the credential. Value is:
Refresh
Type: ConnectApi.Credential
Create an external auth identity provider.
62.0
No
public static ConnectApi.ExternalAuthIdentityProvider createExternalAuthIdentityProvider(ConnectApi.ExternalAuthIdentityProviderInput requestBody)
- requestBody
Type:
ConnectApi.ExternalAuthIdentityProviderInputA
ConnectApi.ExternalAuthIdentityProviderInputinput class.
Type: ConnectApi.ExternalAuthIdentityProvider
Create external auth identity provider credentials.
62.0
No
public static ConnectApi.ExternalAuthIdentityProviderCredentials createExternalAuthIdentityProviderCredentials(String fullName, ConnectApi.ExternalAuthIdentityProviderCredentialsInput requestBody)
- fullName
Type: String
Full name of the external auth identity provider to create credentials for.
- requestBody
Type:
ConnectApi.ExternalAuthIdentityProviderCredentialsInputA
ConnectApi.ExternalAuthIdentityProviderCredentialsInputinput class
Type: ConnectApi.ExternalAuthIdentityProviderCredentials
Create an external credential.
58.0
No
public static ConnectApi.ExternalCredential createExternalCredential(ConnectApi.ExternalCredentialInput requestBody)
- requestBody
Type:
ConnectApi.ExternalCredentialInputInput used to create or update an external credential.
Type: ConnectApi.ExternalCredential
Create a named credential.
58.0
No
public static ConnectApi.NamedCredential createNamedCredential(ConnectApi.NamedCredentialInput requestBody)
- requestBody
Type:
ConnectApi.NamedCredentialInputInput used to create or update a named credential.
Type: ConnectApi.NamedCredential
Delete a credential.
This method deletes the user external credentials that store the encrypted access tokens used for named credential callouts, not the external credential itself. You can delete an external credential only in the UI or by using REST API.
56.0
No
public static Void deleteCredential(String externalCredential, String principalName, ConnectApi.CredentialPrincipalType principalType)
externalCredential
Type: String
Fully qualified developer name of the external credential.
principalName
Type: String
Name of the external credential named principal.
principalType
Type: ConnectApi.CredentialPrincipalType
Type of credential principal. Values are:
AwsStsPrincipalNamedPrincipalPerUserPrincipal
Type: Void
Delete a credential with authentication parameters.
This method deletes the user external credentials that store the encrypted access tokens used for named credential callouts, not the external credential itself. You can delete an external credential only in the UI or by using REST API.
59.0
No
public static Void deleteCredential(String externalCredential, String principalName, ConnectApi.CredentialPrincipalType principalType, List<String> authenticationParameters)
externalCredential
Type: String
Fully qualified developer name of the external credential.
principalName
Type: String
Name of the external credential named principal.
principalType
Type: ConnectApi.CredentialPrincipalType
Type of credential principal. Values are:
AwsStsPrincipalNamedPrincipalPerUserPrincipal
authenticationParameters
Type: List<String>
List of authentication parameters only for custom protocols, for example myApiKey,myApiSecret. If unspecified, all credentials are deleted.
Type: Void
Delete an external auth identity provider.
66.0
No
public static Void deleteExternalAuthIdentityProvider(String developerName)
- developerName
Type: String
Fully qualified developer name of the external auth identity provider.
Type: Void
Delete an external credential.
66.0
No
public static Void deleteExternalCredential(String developerName)
- developerName
Type: String
Fully qualified developer name of the external credential.
Type: Void
Delete a named credential.
66.0
No
public static Void deleteNamedCredential(String developerName)
- developerName
Type: String
Fully qualified developer name of the named credential.
Type: Void
Get a credential.
56.0
No
public static ConnectApi.Credential getCredential(String externalCredential, String principalName, ConnectApi.CredentialPrincipalType principalType)
externalCredential
Type: String
Fully qualified developer name of the external credential.
principalName
Type: String
Name of the external credential named principal.
principalType
Type: ConnectApi.CredentialPrincipalType
Type of credential principal. Values are:
AwsStsPrincipalNamedPrincipalPerUserPrincipal
Type: ConnectApi.Credential
Get an external auth identity provider.
62.0
No
public static ConnectApi.ExternalAuthIdentityProvider getExternalAuthIdentityProvider(String fullName)
- fullName
Type: String
Full name of the external auth identity provider.
Type: ConnectApi.ExternalAuthIdentityProvider
Get external auth identity provider credentials.
62.0
No
public static ConnectApi.ExternalAuthIdentityProviderCredentials getExternalAuthIdentityProviderCredentials(String fullName)
- fullName
Type: String
Full name of the external auth identity provider.
Type: ConnectApi.ExternalAuthIdentityProviderCredentials
Get a list of external auth identity providers in the org.
62.0
No
public static ConnectApi.ExternalAuthIdentityProviderList getExternalAuthIdentityProviders()
Type: ConnectApi.ExternalAuthIdentityProviderList
Get an external credential, including the named credentials and principals associated with it and the type and status of each principal.
56.0
No
public static ConnectApi.ExternalCredential getExternalCredential(String developerName)
- developerName
Type: String
Fully qualified developer name of the external credential.
Type: ConnectApi.ExternalCredential
Get external credentials that the user can authenticate to.
56.0
No
public static ConnectApi.ExternalCredentialList getExternalCredentials()
Type: ConnectApi.ExternalCredentialList
Get a named credential.
59.0
No
public static ConnectApi.NamedCredential getNamedCredential(String developerName)
- developerName
Type: String
Fully qualified developer name of the named credential.
Type: ConnectApi.NamedCredential
Get a list of named credentials for the org.
59.0
No
public static ConnectApi.NamedCredentialList getNamedCredentials()
Type: ConnectApi.NamedCredentialList
Get the URL for the OAuth token flow for an external credential.
56.0
No
public static ConnectApi.OAuthCredentialAuthUrl getOAuthCredentialAuthUrl(ConnectApi.OAuthCredentialAuthUrlInput requestBody)
- requestBody
Type:
ConnectApi.OAuthCredentialAuthUrlInputA
ConnectApi.OAuthCredentialAuthUrlInputclass indicating the OAuth authentication flow.
Type: ConnectApi.OAuthCredentialAuthUrl
Accepts input parameters representing a specific external credential and, optionally, a named principal. Returns the URL a user must visit to begin the authentication flow, ultimately returning authentication tokens to Salesforce. Use this method as part of building a customized or branded user interface to help users initiate authentication.
Update custom credentials.
This method updates custom credentials. To replace a credential, use updateCredential(requestBody).
59.0
No
public static ConnectApi.Credential patchCredential(ConnectApi.CredentialInput requestBody)
- requestBody
Type:
ConnectApi.CredentialInputA
ConnectApi.CredentialInputclass. Only the custom credentials in the input class are updated.
Type: ConnectApi.Credential
Replace a credential.
This method uses the ConnectApi.CredentialInput and the ConnectApi.CredentialValueInput input classes to replace a credential’s values. In the UI, these values appear as the credential’s authentication parameters. To update a credential, use patchCredential(requestBody).
56.0
No
public static ConnectApi.Credential updateCredential(ConnectApi.CredentialInput requestBody)
- requestBody
Type:
ConnectApi.CredentialInputA
ConnectApi.CredentialInputclass.
Type: ConnectApi.Credential
Update an external auth identity provider.
66.0
No
public static ConnectApi.ExternalAuthIdentityProvider updateExternalAuthIdentityProvider(String developerName, ConnectApi.ExternalAuthIdentityProviderInput requestBody)
- developerName
Type: String
Fully qualified developer name of the external auth identity provider.
- requestBody
Type:
ConnectApi.ExternalAuthIdentityProviderInputInput used to create or update an external auth identity provider.
Type: ConnectApi.ExternalAuthIdentityProvider
Replace external auth identity provider credentials.
62.0
No
public static ConnectApi.ExternalAuthIdentityProviderCredentials updateExternalAuthIdentityProviderCredentials(String fullName, ConnectApi.ExternalAuthIdentityProviderCredentialsInput requestBody)
- fullName
Type: String
The external auth identity provider credentials to replace.
- requestBody
Type:
ConnectApi.ExternalAuthIdentityProviderCredentialsInputA
ConnectApi.ExternalAuthIdentityProviderCredentialsInputinput class.
Type: ConnectApi.ExternalAuthIdentityProviderCredentials
Update an external credential.
66.0
No
public static ConnectApi.ExternalCredential updateExternalCredential(String developerName, ConnectApi.ExternalCredentialInput requestBody)
- developerName
Type: String
Fully qualified developer name of the external credential.
- requestBody
Type:
ConnectApi.ExternalCredentialInputInput used to create or update an external credential.
Type: ConnectApi.ExternalCredential
Update a named credential.
66.0
No
public static ConnectApi.NamedCredential updateNamedCredential(String developerName, ConnectApi.NamedCredentialInput requestBody)
- developerName
Type: String
Fully qualified developer name of the named credential.
- requestBody
Type:
ConnectApi.NamedCredentialInputInput used to create or update a named credential.