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.

ConnectApi

These methods are for NamedCredentials. All methods are static.

See Also

Create a credential.

56.0

No

public static ConnectApi.Credential createCredential(ConnectApi.CredentialInput requestBody)

requestBody

Type: ConnectApi.CredentialInput

A ConnectApi.CredentialInput class.

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.ExternalAuthIdentityProviderInput

A ConnectApi.ExternalAuthIdentityProviderInput input 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.ExternalAuthIdentityProviderCredentialsInput

A ConnectApi.ExternalAuthIdentityProviderCredentialsInput input class

Type: ConnectApi.ExternalAuthIdentityProviderCredentials

Create an external credential.

58.0

No

public static ConnectApi.ExternalCredential createExternalCredential(ConnectApi.ExternalCredentialInput requestBody)

requestBody

Type: ConnectApi.ExternalCredentialInput

Input 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.NamedCredentialInput

Input 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:

  • AwsStsPrincipal
  • NamedPrincipal
  • PerUserPrincipal

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:

  • AwsStsPrincipal
  • NamedPrincipal
  • PerUserPrincipal

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:

  • AwsStsPrincipal
  • NamedPrincipal
  • PerUserPrincipal

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.OAuthCredentialAuthUrlInput

A ConnectApi.OAuthCredentialAuthUrlInput class 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.CredentialInput

A ConnectApi.CredentialInput class. 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.CredentialInput

A ConnectApi.CredentialInput class.

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.ExternalAuthIdentityProviderInput

Input 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.ExternalAuthIdentityProviderCredentialsInput

A ConnectApi.ExternalAuthIdentityProviderCredentialsInput input 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.ExternalCredentialInput

Input 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.NamedCredentialInput

Input used to create or update a named credential.

Type: ConnectApi.NamedCredential