Add automatic post-processing

Prev Next

You can add automatic post-processing with some custom business logic. For example, you can configure additional calculations or data updates, then specify a custom toast message for when the specific template is applied.

  1. Create a Lightning component that will provide the handler code for the ApplyTemplateCompletedEvent.

Example of a SampleApplyTemplateEventHandler component:

<aura:component description="SampleApplyTemplateEventHandler"
                implements="flexipage:availableForAllPageTypes">
    <aura:handler event="c:ApplyTemplateCompletedEvent" action="{!c.handleApplyTemplateCompletedEvent}"/>
</aura:component>
  1. Create a SampleApplyTemplateEventHandler controller where you can specify pre- or post-processing actions and a custom toast message.
({
    handleApplyTemplateCompletedEvent: function (component, event, helper) {
        console.log('At the top of handleApplyTemplateCompletedEvent');
 
        // get the params
        let params = event.getParams();
        let templateId = params["templateId"];
        let targetObjectId = params["targetObjectId"];
 
        console.log('templateId: ' + templateId + ' targetObjectId: ' + targetObjectId);
 
        const toastEvent = $A.get("e.force:showToast");
        const successMessage = 'Custom success message - applied template: ' + templateId + 'target: ' + targetObjectId;
 
        toastEvent.setParams({
            type: 'success',
            message: successMessage,
        });
        toastEvent.fire();
        $A.get("e.force:refreshView").fire();
    }
})
  1. Add this component to the Lightning page.
Note
  • By default, the Show Message On Successful Apply checkbox is selected and a standard toast message Template Name was successfully applied appears.
  • You can clear the Show Message On Successful Apply checkbox. In this case, the toast message about a successful template application does not appear.