Skip to content

NamedCredentialRecipes

pozil edited this page May 14, 2024 · 2 revisions

NamedCredentialRecipes

Demonstrates how to manage named credentials from Apex

Group Integration Recipes

Fields

public NAMED_CREDENTIAL_MASTER_LABELString

public NAMED_CREDENTIAL_DEVELOPER_NAMEString

public NAMED_CREDENTIAL_TYPEConnectApi

public NAMED_CREDENTIAL_CALLOUT_URLString

public NAMED_CREDENTIAL_ALLOW_MERGE_FIELDS_IN_BODYBoolean

public NAMED_CREDENTIAL_ALLOW_MERGE_FIELDS_IN_HEADERBoolean

public NAMED_CREDENTIAL_GENERATE_AUTH_HEADERBoolean

public EXTERNAL_CREDENTIAL_MASTER_LABELString

public EXTERNAL_CREDENTIAL_DEVELOPER_NAMEString

public EXTERNAL_CREDENTIAL_AUTHENTICATION_PROTOCOLConnectApi

public PRINCIPAL_NAMEString

public PRINCIPAL_TYPEConnectApi

public PRINCIPAL_SEQUENCE_NUMBERInteger


Methods

public static ConnectApi createNamedCredential(ConnectApiWrapper connectApiWrapper, String permissionSetName)

Demonstrates how create a named credential from Apex.

Parameters

Param Description
connectApiWrapper instance of ConnectApiWrapper, created to allow mocking
permissionSetName name of the permission set that will have access to the external credential

Returns

Type Description
ConnectApi ConnectApi.NamedCredential The created named credential

Example

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());

private static ConnectApi createExternalCredential(ConnectApiWrapper connectApiWrapper, String permissionSetName)

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.

Parameters

Param Description
connectApiWrapper instance of ConnectApiWrapper, created to allow mocking
permissionSetName name of the permission set that will have access to the external credential

Returns

Type Description
ConnectApi ConnectApi.ExternalCredential The created external credential

Example

System.debug(NamedCredentialRecipes.createExternalCredential(new ConnectApiWrapper(), 'Apex_Recipes'));

Clone this wiki locally