Newer Version Available

This content describes an older version of this product. View Latest

Customize the TPM UI EARights

Enable the global editability and visibility of a promotion or tactic by modifying its EARights.
  1. Log in to your Salesforce org, and go to Developer Console.
  2. Create a global Apex class that implements the System.Callable interface.

    Create two different Apex classes to modify the promotion and tactic EARights separately.

    Note

  3. Override the global call method that has these parameters.
    • action: String. The behavior for the method to exhibit.
    • params: Map<String,Object>. Arguments to be used by the specified action. The object is of type List<EARightsAccess>. Each EARightsAccess instance has properties that you can modify. For information on this class, see EARightsAccess Class Reference.

    Here’s the Apex class structure for the promotion and tactic EARights customization.

    1global class <Your Callable Apex Class> implements System.Callable {
    2
    3    global Object call(String action, Map<String, Object> args) {
    4        // Read Transaction Id
    5        String txId = (String) args.get('txId');
    6        // Get the Promotion Id
    7        Id promotionId = args.get('promotionId'); 
    8        // Get the Promotion EARigths
    9        List<cgcloud.EARightsAccess> promotionRights = (List<cgcloud.EARightsAccess>) args.get('EARights');
    10                
    11        // Your custom logic goes here
    12    }
    13}
    1global class <Your Callable Apex Class> implements System.Callable {
    2
    3    global Object call(String action, Map<String, Object> args) {
    4        // Read Transaction Id
    5        String txId = (String) args.get('txId');
    6        // Get the Promotion Id
    7        Id promotionId = args.get('promotionId'); 
    8        // Get the Tactic EARigths
    9        List<cgcloud.EARightsAccess> tacticRights = (List<cgcloud.EARightsAccess>) args.get('EARights');
    10                
    11        // Your custom logic goes here
    12    }
    13}
  4. To modify the EARights associated with a promotion or tactic, edit the properties of the associated EARightsAccess instance in the respective Apex class. For a list of modifiable promotion and tactic EARights, see Modifiable Promotion and Tactic EARights.
    Here’s a sample Apex class that modifies the EARights of the promotion edit button associated with an existing promotion.
    1global class MyEditAccessRightsHook implements System.Callable {
    2
    3    global Object call(String action, Map<String, Object> args) {
    4        // Read Transaction Id
    5        String txId = (String) args.get('txId');
    6        // Get the Promotion Id
    7        Id promotionId = args.get('promotionId'); 
    8        // Get the EARigths
    9        List<cgcloud.EARightsAccess> promotionRights = (List<cgcloud.EARightsAccess>) args.get('EARights');
    10                
    11        // Get the Promotion Template name
    12        List<cgcloud__Promotion__c> promos = [
    13            SELECT cgcloud__Promotion_Template__r.Name
    14            FROM cgcloud__Promotion__c
    15            WHERE Id = :promotionId
    16            LIMIT 1
    17        ];
    18        
    19        // Check if its the target template
    20        Boolean isNoTactics = promos[0].cgcloud__Promotion_Template__r.Name == 'No Tactics';
    21        
    22        // Search the related EARightsAccess instance
    23        for (cgcloud.EARightsAccess acl : promotionRights) {
    24            if (acl.Name == 'PROMOTION_EDIT_BUTTON' && isNoTactics) {
    25                acl.Visible = false;
    26                acl.Editable = false;
    27            }
    28        }
    29        
    30    }
    31}
  5. From Setup, in the Quick Find box, enter Custom Metadata Types, and then expand Custom Metadata Types.
  6. On the CGCloud Process Customization row, click Manage Records.
  7. Click New, complete these fields, and then save your work.

    For promotion EARights customization, fill these details.

    • Label: TPM_Promotion_EARightsAccess_Promotion
    • DeveloperName: TPM_Promotion_EARightsAccess_Promotion
    • Class: <Your Callable Apex Class for modifying the promotion EARights>
    • Method: save
    • Enabled: Select the checkbox.

    For tactic EARights customization, fill these details.

    • Label: TPM_Promotion_EARightsAccess_Tactic
    • DeveloperName: TPM_Promotion_EARightsAccess_Tactic
    • Class: <Your Callable Apex Class for modifyng the tactic EARights>
    • Method: save
    • Enabled: Select the checkbox.
The Apex customization hook is enabled. The call method modifies the EARights of an existing promotion, or tactic based on your custom logic.