Skip to content

In this step, you will:

  • Write custom code that modifies the behavior of the sample record trigger
  • Understand how to write code for different record events

With the development environment set up, you can now modify the HelloWorld trigger in your IDE.

Right now, the HelloWorld trigger has custom logic on the BEFORE_INSERT event. In this step, you will add new custom code to trigger on the AFTER_INSERT event. We’ve already written most of this code for you, so you can focus on the structural updates needed to add code for a new event on an existing trigger.

Unlike the BEFORE_INSERT event which triggers right before the record saves, the AFTER_INSERT event triggers immediately after the record saves. When triggered, this new custom code creates a vsdk_hello_world_child__c record.

Add Custom Code for the AFTER_INSERT Event

Section link for Add Custom Code for the AFTER_INSERT Event
  1. In IntelliJ®, navigate to your project’s home directory.
  2. Open the HelloWorld Java file, which is located in \src\main\java\com\veeva\vault\custom\triggers.
  3. Remove the multi-line comment (/*) on lines 35 and 74. This will uncomment lines 35 through 51, which is code for custom logic on the AFTER_INSERT event.
    Deleting multiline code comments.Deleting multiline code comments.
  4. Before this AFTER_INSERT code will run, you need to add this event to the record trigger annotation. You can do this by adding the event to the @RecordTriggerInfo annotation. In line 13, add RecordEvent.AFTER_INSERT to the event parameter in the annotation:
    Adding the AFTER_INSERT event to the record trigger annotation.Adding the AFTER_INSERT event to the record trigger annotation.

You’ve just written your first piece of SDK code, custom logic for an AFTER_INSERT event! In the next step, you will deploy these changes to your Vault.