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

Introduction

The vsdk-user-defined-model-sample project demonstrates the creation and use of the user-defined model(UDM). User-defined models allow developers to create reusable data access objects, or models, and annotate their getters and setters as user-defined properties. You can use user-defined models with the JsonService to translate data to and from JSON, or with HttpService to send and receive data using REST APIs.

This project will demonstrate how to define and use User-defined models with the QueryService to handle Query responses. Additionally, it will demonstrate how to use User-defined models with the HTTPService to send and receive data. Furthermore, it will demonstrate how to translate data to and from JSON using the JsonService and User-defined models.

This project contains the following Objects, User-defined Models and Triggers:

Objects:

  • vSDK Setting (vsdk_setting__c): An object that contains the custom sdk job settings that the trigger will fetch
  • vSDK UDM Example (vsdk_udm_example__c): The object on whose BEFORE_CREATE and BEFORE_UPDATE the trigger will execute

User-Defined Models

  • SettingRecord Model: A User-defined model that represents a single vsdk_setting__c record from a remote vault
  • ExampleSettings Model: A User-defined Model that represents the settings from Vault
  • RemoteSettingResponse Model: A User-defined model that represents a VQL query response with data from Vault

User-Defined Services

  • CustomSettingService: A User-defined Service used to get and create local and remote vSDK Settings records.

Triggers

  • ExampleUDMTrigger: A Record Trigger which executes on the BEFORE_INSERT or BEFORE_UPDATE event on the vSDK UDM Example Object

Setup

The project contains two separate vault packages (VPK) in the deploy-vpk directory with the necessary Objects, Triggers and Models 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-model-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-model-sample-code.vpk file.

Note: Steps 7- require you to have another Vault in which you will need to have also imported the Vault components for this project. Please repeat steps 3-6 in the second Vault.

  1. Navigate to Admin > Connections and click the Create button. Create a Vault to Vault connection with the following values:

Name: Remote Connection API Name: remote_connection Authorized Connection User: Your Vault User from the picklist

  1. Download the Connection file from your newly created connection from the Actions menu (gear icon) and clicking the Download Connection File option
  1. Repeat Step 7 in your remote vault

  2. Upload the Connection File from Step 8 by clicking the Connect From File option in the the Actions menu (gear icon) of your connection from Step 9.

  3. Approve the connection in both vaults.

Run the project

To run the project, create a new vSDK User-Defined Model Object by navigating to Admin > Business Admin > vSDK UDM Examples. Create a vSDK UDM Example, specify a name and select the Remote Connection as created in the steps prior. You will see the results update with the vSDK Setting values from the local and remote vaults.