-
Notifications
You must be signed in to change notification settings - Fork 519
NamedCredentialRecipes
pozil edited this page Nov 14, 2024
·
5 revisions
Demonstrates how to manage named credentials from Apex
Group Integration Recipes
public static final NAMED_CREDENTIAL_MASTER_LABELString
public static final NAMED_CREDENTIAL_DEVELOPER_NAMEString
public static final NAMED_CREDENTIAL_TYPEConnectApi.NamedCredentialType
public static final NAMED_CREDENTIAL_CALLOUT_URLString
public static final NAMED_CREDENTIAL_ALLOW_MERGE_FIELDS_IN_BODYBoolean
public static final NAMED_CREDENTIAL_ALLOW_MERGE_FIELDS_IN_HEADERBoolean
public static final NAMED_CREDENTIAL_GENERATE_AUTH_HEADERBoolean
public static final EXTERNAL_CREDENTIAL_MASTER_LABELString
public static final EXTERNAL_CREDENTIAL_DEVELOPER_NAMEString
public static final EXTERNAL_CREDENTIAL_AUTHENTICATION_PROTOCOLConnectApi.CredentialAuthenticationProtocol
public static final PRINCIPAL_NAMEString
public static final PRINCIPAL_TYPEConnectApi.CredentialPrincipalType
public static final PRINCIPAL_SEQUENCE_NUMBERInteger
Demonstrates how create a named credential from Apex.
public static ConnectApi.NamedCredential createNamedCredential(ConnectApiWrapper connectApiWrapper, String permissionSetName)| Name | Type | Description |
|---|---|---|
| connectApiWrapper | ConnectApiWrapper | instance of ConnectApiWrapper, created to allow mocking |
| permissionSetName | String | name of the permission set that will have access to the external credential |
ConnectApi.NamedCredential
The created named credential
System.debug(NamedCredentialRecipes.createNamedCredential(new ConnectApiWrapper(), 'Apex_Recipes'));
HttpResponse response = RestClient.makeApiCall(
NAMED_CREDENTIAL_DEVELOPER_NAME,
RestClient.HttpVerb.GET,
'/volumes?q=salesforce'
);
System.debug(response.getBody());This example shows how to create an external credential in Apex. An external credential contains the authentication and authorization information for the callout, and needs to be linked to a named credential in order to be used.
private static ConnectApi.ExternalCredential createExternalCredential(ConnectApiWrapper connectApiWrapper, String permissionSetName)| Name | Type | Description |
|---|---|---|
| connectApiWrapper | ConnectApiWrapper | instance of ConnectApiWrapper, created to allow mocking |
| permissionSetName | String | name of the permission set that will have access to the external credential |
ConnectApi.ExternalCredential
The created external credential
System.debug(NamedCredentialRecipes.createExternalCredential(new ConnectApiWrapper(), 'Apex_Recipes'));