Skip navigation links

Package com.veeva.vault.sdk.api.notification

This package provides interfaces to send Vault notifications.

See: Description

Package com.veeva.vault.sdk.api.notification Description

This package provides interfaces to send Vault notifications.


You can create notifications that Vault sends to users as both emails and in-application notifications. You can send notifications to: Note that Persons cannot receive in-application notifications and receive email notifications only.

A notification has three parts:

You can also set templates for your notifications, which is useful for translating your notifications across multiple languages. Learn more about creating message templates in Vault Help.


Notification templates, text, messages, and subjects can all include tokens. Tokens are written in a specific format which Vault replaces with the values the token represents. For example, ${recipientName} inserts the Name value of the recipient. You can view the full list of tokens in Vault Help.

Note that many standard tokens are specific to some context. For example, ${docName}, ${Object.name__v}, and ${taskName} are specific to a document, object, or workflow, respectively. Because notifications created with the SDK are not associated with a context, these tokens will resolve as empty Strings.

You can also create custom tokens, which must be in the format ${Custom.tokenName}. You can set the value of a custom token in NotificationMessage.setTokenValue(java.lang.String, java.lang.String) and NotificationTemplate.setTokenValue(java.lang.String, java.lang.String).

You can also resolve token values by implementing a Consumer of TokenResolverInput, and setting the Consumer to the NotificationTemplate with NotificationTemplate.setTokenResolver(java.util.function.Consumer). In your implementation, the resolved token values should be set to TokenResolverOutput.

If the message recipient is a Person (person__sys), recipient tokens resolve to System values. For example, ${recipientFirstName} will resolve as "System", and ${recipientMobilePhone} will resolve as an empty String. To include information about a Person such as Person.first_name_sys, use RecordService to retrieve the Person record and Record.getValue(java.lang.String, com.veeva.vault.sdk.api.core.ValueType) to get the field value. Then you can add this value to your NotificationMessage or NotificationTemplate as a custom token.

Learn more about tokens in NotificationMessage.

Example Notification

The following example sends a notification from a template, both as an email and within the Vault UI.
          //Get your recipient userIds, Groups, and RecordRoles
          Set<String> recipients = VaultCollections.newSet();

          GroupService groupService = ServiceLocator.locate(GroupService.class);
          List groupNames = VaultCollections.newList();
          GetGroupsResponse groupResponse = groupService.getGroupsByNames(groupNames);
          Group group = groupResponse.getGroupByName("sdk_group__c");
          List groups = VaultCollections.newList();

          RecordService recordService = ServiceLocator.locate(RecordService.class);
          Record record = recordService.newRecordWithId("study__v", studyId);
          List records = VaultCollections.newList();

          RecordRoleService recordRoleService = ServiceLocator.locate(RecordRoleService.class);
          GetRecordRolesResponse recordRoleResponse = recordRoleService.getRecordRoles(records);
          RecordRole recordRole = recordRoleResponse.getRecordRole(record, "viewer__v");
          List recordRoles = VaultCollections.newList();

          NotificationService notificationService = ServiceLocator.locate(NotificationService.class);

          NotificationParameters notificationParameters = notificationService.newNotificationParameters();

          NotificationTemplate template = notificationService.newNotificationTemplate()
          .setTokenValue("productName", productName);

          //Send Notification with a NotificationTemplate
          notificationService.send(notificationParameters, template);

Example Notification Template

In the example above, the templateName product_change_notification_template__c is the name of a template created by an Admin in Vault. Below is an example of what this template may look like:
         Hello ${recipientName},

         The product ${Custom.productName} profile has been modified. Please review the changes.


Example Token Resolver Consumer

The following example implements a Consumer to resolve token values.
      public class NotificationTokenResolver implements Consumer<TokenResolverInput> {

          public void accept(TokenResolverInput tokenResolverInput) {
              TokenResolverOutput output = tokenResolverInput.getTokenResolverOutput();

              // resolve tokens for template "product_change_notification_template__c".
              Map<String, String> tokenValues = VaultCollections.newMap();
              tokenValues.put("productName", productName);
              output.setTokenValues("en", tokenValues);

Example Set Consumer

In the Notification example above, you can set the Consumer to the NotificationTemplate, instead of calling setTokenValue.
           NotificationTemplate template = notificationService.newNotificationTemplate()
           .setTokenResolver(new NotificationTokenResolver());
Skip navigation links

Copyright © Veeva Systems 2017–2021. All rights reserved.