How to Use the Loop.LoopMessage Class in an Apex Trigger

Salesforce developers commonly inquire about the ability to trigger a DDP using custom Apex code. Is this possible? Yes! Below I’ll walk you through the basic setup and provide you with sample code. This example will generate an Invoice template and delivery via email when a Opportunity record is edited and the Stage field is ‘Proposal/Price Quote’.

Part 1: Create the DDP & Delivery Option
Part 2: Create the Apex Class
Part 3: Create the Trigger
Part 4: Test!

Downloads:

Get the Apex Class here: Apex Class – MySender
Get the Trigger here: Trigger – MySender

Part 1: Create the DDP & Delivery Option

The code used in this example will require you to have a DDP with the name ‘Invoice’. Additionally, you will need a Delivery Option on this DDP with the name Email. The Additional To field on the Email delivery option will need to contain a email address OR a field tag for a User/Contacts email address. This email address will receive the generated document when the code is executed so be sure to have access to the inbox.

Part 2: Create the Apex Class

  1. Go to Setup > Develop > Apex Classes > click the New button
    New_Apex__Class
  2. Enter your custom code
  3. Click ‘Save’
    Apex_Class_Code

Part 3: Create the Trigger

  1. Go to Setup > Customize > Opportunities > Triggers > Click the ‘New’ buttonNew_Trigger
  2. Enter your custom code
  3. Click ‘Save’

Part 4: Test!

At this point, you were able to save the Apex Class and Trigger containing the code without receiving an error.  Good job! Now test the code by navigating to a Opportunity record and editing the Stage to ‘Proposal/Price Quote’.

Don’t see the generated document in your inbox? If you do not receive the email containing the generated document there is most likely an issue with the code or the DDP configuration. View the Job Queue by navigating to DDP Admin tab and clicking the ‘Job Queue’ button. If you do not see any information the issue is most likely with your code. Otherwise, you will see the job is either Pending or has an Error.

Job_Queue_Status

 

 

4x Certified Salesforce Administrator. Nintex Drawloop Expert.