Loading
Prepare for Email to Become the Default Login ExperienceRead More
Get Started with Communications, Media, and Energy & Utilities (CME)...
UserNotifier Implementation

UserNotifier Implementation

Abstracts the notification framework used when sending notifications. You can invoke this implementation to send job completion or alert notification to the users.

Interface

VlocityOpenInterface

Type

Loosely typed

Triggered When

Invoked after the completion of asynchronous batch actions in the multi-site and bulk-ordering flows. These batch actions include ApplyToGroup, PriceAndValidate, and CreateAndSubmitOrders. You can use this implementation to trigger any kind of notifications.

Signature

Access

Signature

public

vlocity_cmt.VOIInvoker.invokeMethod('UserNotifier', input, output, options);

Default Implementation

The DefaultUserNotifierImplementation sends out of the box Salesforce app notifications.

Other Implementations

None.

Input Parameters

A map containing the following key and value pairs:

Input Field

Data Type

Description

title

String

Title of the notification.

body

String

Body of the notification.

userID

List <String> or String

Recipients of the notification. Use List if there’s more than one recipient.

customNotificationTypeName

String

Custom metadata for sending notifications.

Follow the instructions in Create a Notification Type to create your notification type.

targetID

String

Salesforce record ID.

Specifies the record ID for which the notification is generated.

targetPageRef

String

Target page reference URL.

Sample Input

{  "appNotification":
  { 
   "title": "Job completed",    
   "body": "Job completed successfully",
   "userID": [      "0054x0000011IbJAAU"    ],    
   "customNotificationTypeName": "CMEbatchJob",
   "targetID": "8014x000000M7hYAAS"  
  }
}

Output Parameters

A map object containing the keys suffixed with a status message for each notification.

Sample Output

{  
    "appNotification": "OK",  
    "emailNotificationError": "Required field To  missing. Provide the parameter."
}

Sample Implementation

global class SampleUserNotifierImplementation implements vlocity_cmt.VlocityOpenInterface
{
public Boolean invokeMethod(
       String methodName, 
       Map<String, Object> inputMap, 
       Map<String, Object> outputMap, 
       Map<String, Object> options)
   {
       /*
        * check for cpq boolean flag before sending notification
        */
       if(CustomSettingsUtilities.getCpqConfigurationSetupBooleanValue('EnableUserNotifier',true))
       {
            if(methodName != null)
            {
                // check the method being invoked
                if(methodName.equalsIgnoreCase('sendNotifications'))
                {
                    return sendNotifications(inputMap, outputMap, options);
                }
            }
       }
       else
       {
        outputMap.put('error','Notifications aren’t enabled');
       }
       return false;
   }
   private static Boolean sendNotifications(
       Map<String, Object> input, 
       Map<String, Object> output, 
       Map<String, Object> options)
   {
       //channels to send notifications
       // add your own channels to the input 
       // and add a method for them.
       Set<String> channelsToSendNotifs = new Set<String>();
       channelsToSendNotifs = input.keySet();
       List<String> notifiersToCall = new List<String>();
       Boolean allNotifsSuccess = true;
       for (String channel : channelsToSendNotifs) 
       {
           if(channel.equals('appNotification'))
           {
                notifiersToCall.add('appNotification');
           }
           // add more methods here 
           else
           {
                allNotifsSuccess = false;
                output.put(channel,'Channel not found');
           }
        }
    for(String notifier : notifiersToCall)
       {
            Boolean ableToSend = false;
            try
            {
                if(notifier == 'appNotification')
                {
                    ableToSend = sendAppNotification((Map<String, Object>) input.get('appNotification'));
                }
                // add more notifier channels here 
            }
            catch(Exception e)
            {
                String outKey = notifier + 'Error';
                String outVal = String.valueOf(e);
                output.put(outKey,outVal);
            }
            finally
            {
                if(!ableToSend)
                {
                    allNotifsSuccess = false;
                }
                else
                {
                    String outKey = notifier;
                    output.put(outKey,'OK');
                }
            }       
        }
       
       return allNotifsSuccess;
    }
    private static Boolean sendAppNotification(Map<String,Object> inputCustomNotification)
    {
       // create your implementation of app notification
    }
    // add any more channel methods
       
}
 
Loading
Salesforce Help | Article