Automate generating different documents using Decision Trees in Salesforce Flow

Drive Connect Automation allows users to automatically generate a Drive Connect template and link it to the Drive Links component by selecting the New File from Template operation in a Record-Triggered flow. This article will show you an example of how you can create different documents based on fields in Salesforce using Decision Trees.

The Use Case

In this example, we will be creating a record triggered flow that will run based on a condition of a stage of the opportunity. Within the flow, there will be a decision tree that will determine which Automate Drive action will run.

Creating the flow

  1. First we will create a record triggered flow that will trigger only when the opportunity stage is set to Negotiation/Review
  2. Next, we will add a decision tree node.
    1. This node will have 2 outcomes based on the Opportunity Type field:
      1. Existing Business
      2. New Business
    2. To find the opportunity type field, first you must choose the global variable called “$Record” and then you will search for the field you want your decision to be based off of. In this case it is the Opportunity Type field
    3. Once you have your two outcomes, you can save this and two outcomes will be added to the overall flow
  3. Finally, we will add Automate Drive Apex Actions to each decision node. We will work on the Existing Business outcome first.
    1. Add an action for the Existing Business outcome
    2. Search for the Automate Drive Action
    3. Choose the File from Template option
    4. Add the template meant for the existing business outcome, which is “Existing Business Agreement” in this example
    5. Follow the same steps but this time for the New Business outcome and using the template meant for that specific outcome. The end result will have two Apex actions, one under each outcome.
  4. Save your flow and activate it.

The Results

Now that our flow is activated, we can test it out using two opportunities. The first opportunity is an opportunity where the Opportunity Type Field is set to New.

Once we set the opportunity stage to Negotiation/Review, the flow will run. It will then look for the Opportunity Stage and since it’s set to new, it will generate New Client Agreement.

Now let’s look at another opportunity where the Opportunity Type Field is set to Existing.

If we flip the stage to Negotiation/Review, the same flow will run, but it will generate the Existing Client Agreement document based on the Opportunity Type Field set to Existing.

This was an example on how you can have different documents generate based on fields in Salesforce using decision trees and Salesforce flows.