Configure custom actions
  • 04 Nov 2023
  • 5 Minutes to read
  • Dark
    Light

Configure custom actions

  • Dark
    Light

Article summary

You can add custom actions to the following Deal Manager components:

  • Add Lines
  • Line Items
  • Workspace

Define a custom action for a specific Product Selector Configuration. Once defined, the action will appear only on the component associated with that Product Selector Configuration.

Tip

If you want to configure custom actions for the Edit Lines modal, follow the steps in Replace Save button with a custom action.

There are two different ways to create the event handler for a custom action button:

  • Use a defined Mass Edit Policy Type handler.
  • Develop a custom Lightning component handler.

About the Mass Edit Policy Type handler

The Mass Edit configurable feature enables one or more Mass Edit Types for users to run formulaic, bulk edits on selected line items. You can make one or more of those custom actions available as buttons. A custom action that is configured by using a Mass Edit Policy Type has a very contained architecture and scope; therefore, it does not have the maintenance risks associated with a custom component action.

Consider enabling this feature when a specific Mass Edit action is used frequently. For more information, see Mass edit.

About custom Lightning components

Using a custom Lightning component for a custom action is flexible, but comes with potential risks. Because the component uses custom code, it cannot be tested or guaranteed for future Salesforce platform upgrades.

Note

Zilliant recommends you configure custom actions only in exceptional circumstances. Before implementing a custom action for a customer, discuss the risks and develop a plan to maintain and verify the custom action.

Prerequisites

Before configuring this feature, make sure that the following fields on the Action Configuration object are visible and can be edited:

  • Action Component
  • Action Order
  • Action Type
  • Button Variant
  • Conditional Display Field
  • Action Event Handler Name
  • Action Event Handler Type
  • Event Payload
  • Icon
  • Is Enabled
  • Requires Createable
  • Requires Deletable
  • Requires Editable

If a field is not visible or can't be edited, confirm it has been added to the object's page layout and is visible in the user's profile. For detailed instructions on how to add fields and check for visibility, refer to Make fields visible or editable.

Use Mass Edit Policy Type for event handling in Line Items

Follow these steps for custom action buttons that appear in the Line Items component and Workspace:

  1. Ensure that the Mass Edit Policy Type you want to use as the event handler is defined. For more information, refer to Mass edit.
  2. From the Lightning App Launcher, go to the appropriate Product Selector Configuration.
  3. On the Additional Configurations tab, select the Action Configurations section, then select New.
  4. In the New Action Configuration dialog enter or select values:
    • Action Name—Specify a label for the action button.

    • Icon—Optionally specify a standard Salesforce icon to be shown on the button, in the format:

      <category>:<icon name>
      
    • Product Selector Configuration—Leave the default value.

    • Conditional Display—Optionally specify the API name of the Boolean field on header object (Agreement or Quote) to control when the button should be displayed. If you leave the field blank, the button always appears.

    • Is Enabled—Select this checkbox if you want the action button to be active even if no line items are selected.

      Notes
      • The Is Enabled checkbox affects only agreements and quotes that use the Line Items and Add Lines components to list, add, and edit line items.
      • This checkbox does not affect row-based custom actions available from the dropdown action list on each line item row.
    • Requires Createable—Select to allow the action button to be used only for line items with the corresponding creatable status for a specific user.

    • Requires Editable—Select to allow the action button to be used only for line items with the corresponding editable status for a specific user.

    • Requires Deletable—Select to allow the action button to be used only for line items with the corresponding deletable status for a specific user.

    • Action Event Handler Type—Select the Mass Edit Policy option to point the custom event to the Mass Edit Policy Type.

    • Action Event Handler Name—Enter placeholder text for that field to be automatically and correctly updated.

      Notes

      The handler for all the Mass Edit Policies is zpl:MassEditPolicyActionEventHandler. It exists in the Deal Manager package.

    • Button Variant—Select how you want the button to appear. The default value is Neutral.

    • Event Payload—Specify a value for the massEditPolicyTypeId parameter. The value must be a valid Mass Edit Policy Type Id to which you want to point this custom event.

    • Action Component—Select Line Items or Workspace. If you do not select one of these values, validation will fail.

    • Action Type—Specify the type of the action button:

      • List Button and Button Menu Item handle the selected rows.
      • Row Button appears on each row of the grid.
    • Action Order—Specify the order in which this action item will appear among the rendered set of defined action buttons and menu items.

Note
  • If the Mass Edit Policy Type has parameters, the user will be prompted to enter those parameters before processing the selected lines.
  • If the Mass Edit Policy Type does not have parameters, processing of the selected lines will begin automatically.
  1. Select Save.

Add a custom Lightning component for event handling

Use the same steps to create New Action Configuration as described in Use Mass Edit Policy Type for event handling in Line Items, except for the following fields:

  1. From the Action Event Handler Type dropdown, select Custom.
  2. In the Action Event Handler Name field, specify the name of the custom Lightning component that will handle the event on the action button. This component must implement the zpl:ActionEventHandler interface and handle events in the handleEvent controller function.
  3. In the Event Payload field, optionally specify the payload that you want to pass inside of the action handler, in JSON format.
  4. From the Action Component dropdown, select Line Items or Workspace.
  5. Select Save.

Create a custom Lightning component

You must create a Lightning component to provide handler code for the action button. This Lightning component must implement the zpl:ActionEventHandler interface:

 <aura:interface access="global" description="Interface for a components that handle configured custom action events.">
         <aura:method name="handleEvent" access="global" description="Callback method called when action event is raised.">
                <aura:attribute name="records" type="Map[]" access="global" description="Selected records."/>
                <aura:attribute name="parentId" type="Id" access="global" description="ID of the header object."/>
                <aura:attribute name="payload" type="Map" access="global" description="Data attached to the event"/>
            </aura:method>
        </aura:interface>

The new component must have a controller function named handleEvent. The handleEvent function has access to the selected records, the header object ID, and a payload that is pre-configured in the Action Configuration.

Example of the CustomActionEventHandler component:

<aura:component description="CustomActionEventHandler" implements="zpl:ActionEventHandler">
</aura:component>

CustomActionEventHandler controller:

({
    handleEvent: function (component, event) {
        const params = event.getParam('arguments');
        if (!params) return;
 
        const toastEvent = $A.get("e.force:showToast");
        toastEvent.setParams({
            title: "Success!",
            message: JSON.stringify(params.records.map(e => e.Id)),
            type: "success"
        });
 
        toastEvent.fire();
    }
});

Was this article helpful?

Changing your password will log you out immediately. Use the new password to log back in.
First name must have atleast 2 characters. Numbers and special characters are not allowed.
Last name must have atleast 1 characters. Numbers and special characters are not allowed.
Enter a valid email
Enter a valid password
Your profile has been successfully updated.