Skip to content
smehta-veeva edited this page Jun 9, 2021 · 3 revisions

Introduction

The vsdk-user-defined-service-sample project demonstrates the creation and usage of User-defined services (UDS). User-defined services allow you to wrap reusable logic into a service that can be used by other Vault Java SDK code, such as triggers, actions, or user-defined classes. The main benefit of using user-defined services is that any memory used in a user defined service method is decremented from the total memory limit when the method exits. Only the memory used by the method return value counts toward the memory limit. Since user-defined services are stateless, nothing is retained beyond the service method execution.

This project will demonstrate the usage of the use of a user-defined service ProductSearchUserDefinedService with a SDK trigger. The Trigger will accomplish the following:

  • Validate that the product entered by a user in a bicycle part order object record exists by using the doProductsExist method provided by the user defined service.
  • Reduce the quantity of bicycle part object record found by the doesProductExist method by the amount provided by the user in the Bicycle Part Order record.

Objects

  • Bicycle Part Order (bicycle_part_order__c)
  • Bicycle Part Manufacturer (bicycle_part_manufacturer__c)
  • Bicycle Part (bicycle_model__c)

Setup

The project contains two separate vault packages (VPK) in the deploy-vpk directory with the necessary Objects, and Triggers required for this project.

  1. Clone or download the sample Maven project vSDK User Defined Service Sample project from Github.
  2. Run through the Getting Started guide to setup your development environment.
  3. Log in to your vault and navigate to Admin > Deployment > Inbound Packages and click Import:
  4. Locate and select the following file in your downloaded project file:

Deploy vault components: Select the \deploy-vpk\components\vsdk-user-defined-service-sample-components.vpk file.

  1. From the Actions menu (gear icon), select Review & Deploy. Vault displays a list of all components in the package. You can safely ignore any warnings that may appear.

Review the prompts to deploy the package. You will receive an email when vault completes the deployment.

  1. Repeat steps 3-6 for the vault code:

Custom Trigger code: \deploy-vpk\code\vsdk-user-defined-service-sample-code.vpk file.

Run the project

To run the project, create a new Bicycle Order by navigating to Admin > Business Admin > Bicycle Part Orders:

In this sample, we will create a Bicycle Part Order for Nitro Racing Bicycle Brakes from the Nitro Racing Bicycle Parts part manufacturer with an order quantity of 10. Prior to creating this order with these parameters, we can validate that the part quantity is 100:

After creating a bicycle order with the desired parameters , it can noted that part quantity decreases by the order quantity of 10: