documentation logo
All you’ll ever need to know about Declarative Webhooks and how to get started.

Pages

Advanced settings for building the URL, Headers or Authentication fields

Callout URLs and headers aren’t always static. Same for some of the authentication fields. In some cases, you may need to dynamically set URL parameters or headers based on record details or specific settings in your org. With Declarative Webhooks, you can easily merge dynamic values into the URL and headers and even authentication fields.  

 

Merging fields from the main record or related records (URL and headers)

You can include merge fields from the selected Salesforce Main Object in your Callout URL or headers. In the example below, we’ve configured a Callout URL for Google Maps, using the street, city, state, and zip code fields from the Account object. Remember, field names must be entered as their API field name (not the label), for example: {!APIFIELD}.

To reference a field from a related object, use the following format: {!Custom_Relation__r.Custom_Field__c}. For example, if the main object is Contact, you can merge the parent account’s name using this format: {!Account.Name}.  

 

Merging custom metadata values (URL, headers and Authentication fields)

If you need to include a custom metadata field in the URL, you can merge it using this format: {!$CustomMetadata.CustomMetadataTypeAPIName.RecordAPIName.FieldAPIName}.

For example: {!$CustomMetadata.Metadata__mdt.Record1.Field1__c}  

 

Merging custom setting values (URL, headers and Authentication fields)

If you need to include a field from a List Custom Setting, you can merge it using this format: {!$CustomSetting.CustomSettingAPIName.RecordName.FieldAPIName}.

For example: {!$CustomSetting.List_CS__c.Record1.Field1__c}

If you need to include a field from a Hierarchy Custom Setting, you can merge it using this format: {!$CustomSetting.CustomSettingAPIName.FieldAPIName}. You don’t need to specify the record name because it will use the record best matching the running user.

For example: {!$CustomSetting.Hierarchy_CS__c.Field1__c}  

 

Generate the URL using an apex class

If the URL is too complex, you also have the option to generate it using an Apex class. Click on the edit icon on the right side of the URL input.

Switch from Manually entered URL to Built using an Apex Class, then enter the class name that will generate the URL.

The class needs to be global and extend the d_wh.GenerateStringCallable abstract class.

Below is an example class that can be used to generate the URL:

global class TestCallable extends d_wh.GenerateStringCallable {

    global override String Generate(List<Id> mainRecordIds) {

        // Add code to generate and return the callout URL
        Account acc = [SELECT Id, Name FROM Account WHERE Id = :mainRecordIds[0]];

        return 'https://www.google.com/search?q=' + acc.Name;

    }

}

The Generate method receives the Id(s) of the main records used to make the callout. If the callout is a “One Record” type, the list will contain one Id. If no Main Object is selected, the list will be empty.

The value returned by the Generate method will be used as the URL of the callout.  

 

Generate a header value using an apex class

If the header value is too complex, you have the option to generate a header value using an Apex class. In the Header Value item, click on the edit icon.

This will open the Header Value popup. Switch from Manually entered Header Value to Built using an Apex Class, then enter the class name that will generate the header value.

The class needs to be global and extend the d_wh.GenerateStringCallable abstract class.

Below is an example class that can be used to generate the header value.

global class TestCallable extends d_wh.GenerateStringCallable {

    global override String Generate(List<Id> mainRecordIds) {

        // Add code generate and return the header value

        // return mainRecordIds[0];

    }

}

The mainRecordIds parameter contains the list of ids of the main record(s). If the callout is a “One Record” type, the list will contain one Id. If no Main Object is selected, the list will be empty.

The response should be a string and is going to be used as the header value when the callout is made.