---
title: "Decision Trees - Appiphony"
url: "https://appiphony.com/docs/share-connect/integrations/merge-connect/decision-trees"
description: "This article will show you an example of how you can create different documents based on fields in Salesforce using Decision Trees in a Flow."
---

# Decision Trees

Share Connect Automation allows users to automatically generate a Share Connect template and link it to the SharePoint Links component by selecting **New File** from the 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.

### Automate Generating Different Documents using Decision Trees in Salesforce Flow

In this example, we will create a record-triggered flow that runs based on the condition of an Opportunity’s stage. Within the flow, there will be a decision tree that will determine which Automate Share action will run.

1. Navigate to **Salesforce Setup.**
2. In the search box, type **"F****lows"** and go to the Flow page. Choose **New Flow** in the top right corner.
3. We will create a **Record-Triggered Flow**, meaning that when a record is created or updated, this flow will automatically run. For this example, let’s say we only want our Flow to trigger when the opportunity stage is set to Negotiation/Review.
4. Under **Configure Start**, select:
   - Object – **Opportunity**
   - Trigger a flow when – **A record is updated**
   - Condition Requirements – **All conditions are met (AND)**
   - Field – **StageName**
   - Operator – **Equals**
   - Value – **Negotiation/Review**
   - When to Run… – **Only when a record is updated to meet the condition requirements**
5. Next, back in the Flow screen, we will add a **Decision Tree node**. This node will have 2 outcomes based on the Opportunity Type field: **Existing Business**, and **New Business.**
6. In your **New Decision** node, set the following:
   - Label – **New or Existing Business**
   - Outcome Label – **Existing Business**
   - Condition Requirements – **All conditions are met (AND)**
   - Resource – To find the Opportunity type field, you must first choose the global variable called **$Record.** Then you will search for the field you want your decision to be based on. In this case, it is the **Opportunity Type** field.
   - Operator – **Equals**
   - Value – **Existing Business**
7. Click the **(+)** next to Outcome Order.
8. In your **New Outcome**, set the following:
   - Outcome Label – **New Business**
   - Condition Requirements – **Any Conditions are Met (OR)**
   - Resource – To find the Opportunity type field, you must first choose the global variable called **Triggering Opportunity**. Then search for the field you want your decision to be based on. In this case, it is the **Opportunity Type** field.
   - Operator – **Equals**
   - Value – **New Business**
9. Finally, we will add **Automate Share Apex Actions** to each decision node. Let’s start with the **Existing Business** outcome.
   - Add an action for the **Existing Business outcome.**
   - Search for the **Automate Share Action**
   - Choose the **File from Template** option
   - Add the template meant for the existing business outcome, which, in this example, is “Existing Business Agreement”.
10. Repeat the previous four steps under the **New Business outcome** while using the template intended for that outcome. The end result will have two Apex actions, one under each outcome.
11. Click **Save and Activate**.

### Testing the Flow

1. Now that our Flow is activated, we can test it using two opportunities. The first Opportunity has an Opportunity Type Field set to **New Business**.
2. 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 a New Client Agreement.
3. Let’s look at another Opportunity where the Opportunity Type Field is set to **Existing**.
4. If we flip the stage to Negotiation/Review, the same flow will run, but it will now generate an Existing Client Agreement because the Opportunity Type Field is set to **Existing**.
