SFDC Flow Builder: Update Opportunities

When a PandaDoc document is completed, the opportunity stage will be updated to “Closed Won”, and the close date will be automatically set to the current date.

This is just one example; other similar use cases can also be addressed using the Flow approach.

Requirements

  • A Salesforce organization with PandaDoc for Salesforce installed
  • A PandaDoc subscription (Enterprise or Business)
  • A PandaDoc workspace connected to Salesforce (Salesforce Lightning. Install and configure PandaDoc). Ensure that PandaDoc is installed and configured.

Navigate to Flow Builder in Salesforce Lightning

On the Salesforce home page, click the “Setup” icon. Then, select the “Setup” option.

Search for “flow” in the input field in the top left corner. Then, click on “Flows” under “Process Automation”.


How It Works

The purpose of Flow Builder is to customize and automate your workflows within Salesforce. It allows you to create conditional workflows that can automate various steps in your processes, helping you streamline actions in one centralized location. By using Flow Builder, you can set up automated triggers and actions without relying on external tools, ensuring smooth integration with PandaDoc and other systems.

Create a new Flow

On the “Flows” setup page, click “New Flow.”

Choose the “Start From Scratch” option and click “Next”.

When creating a new Flow, you will be prompted to choose its type, which determines how the Flow is launched. In this case, since we want to update Opportunities when the PandaDoc document is completed, select the “Record-Triggered Flow” type.

Click “Create”.

Configure the Start element of the Record-Triggered Flow:

In the “Select Option” section, choose "PandaDoc Document" from the “Object” dropdown.

Next, in the “Configure Trigger” section, choose the option “A record is created or updated”.


Choose the following settings in the “Set Entry Conditions” section:

  • Condition Requirements:
    • Opportunity (pandadoc__Opportunity__c) is not null.
    • Is Deleted (pandadoc__Is_Deleted__c) equals False.
      • These conditions ensure that only documents created from an Opportunity, and that are not deleted, will trigger the flow.
  • When to Run the Flow for Updated Records:
    • Every time a record is updated and meets the condition requirements.
  • Optimize the Flow for:
    • Actions and Related Records

Click “Save” in the top-right corner, give the Flow a name, and then save it.

Create the Flow logic

Once you have configured the Start element of the Flow and saved it, you can begin adding Flow elements.

Our goal is to update the related Opportunity record when the PandaDoc document is marked as completed. Additionally, we may want to perform different updates based on the document's template.

  1. Add the “Decision” element.
  • Name the first outcome (e.g., “True”) and specify the following conditions:

  • Condition Requirements to Execute Outcome:

    • pandadoc__PandaDocDocument__c > Status equals "document.completed".

      • pandadoc__PandaDocDocument__c > Template Id equals "<YOUR_TEMPLATE_ID>".
        (You can skip the template condition if you want the same updates to apply to all documents)
        To find the template ID, go to PandaDoc > Templates, open the desired template, and copy the last part of the URL:

  • When to Execute Outcome:

    • Only if the record that triggered the flow is updated to meet the condition requirements
      (This ensures that the flow only executes the update when the document status is changed to "document.completed.")

Now, add the “Update Records” element to the positive outcome path of the decision.

Configure the “Update Records” element as follows:

  • How to Find Records to Update and Set Their Values:
    • Update records related to the PandaDoc document record that triggered the flow.
  • Records Related to PandaDoc Document:
    • pandadoc__PandaDocDocument__c > Opportunity (Retrieve the related Opportunity from the lookup field).
  • Condition Requirements to Update Record:
    • None - Update all related records. (If you want to update records only when the Opportunity meets specific criteria, you can specify those conditions here).
  • Set Field Values for the Opportunity Records:
    • StageName ← “Closed Won”
    • CloseDate ← $Flow.CurrentDate

Configure the “Update Records” element as follows:

  • How to Find Records to Update and Set Their Values:
    • Update records related to the PandaDoc document record that triggered the flow.
  • Records Related to PandaDoc Document:
    • pandadoc__PandaDocDocument__c > Opportunity (Retrieve the related Opportunity from the lookup field).
  • Condition Requirements to Update Record:
    • None - Update all related records. (If you want to update records only when the Opportunity meets specific criteria, you can specify those conditions here).
  • Set Field Values for the Opportunity Records:
    • StageName ← “Closed Won”
    • CloseDate ← $Flow.CurrentDate

The final flow is as follows:

To activate the flow, you need to save the current version and then activate it.

📢

PLEASE READ

You may want to update other related objects linked to the document, such as the Account or a custom object. This example flow can be adjusted to leverage these updates.

The pandadoc__PandaDocDocument__c object contains several fields that can be used in flow conditions or to find the records to update:

  • pandadoc__Opportunity__c, pandadoc__Account__c, pandadoc__Contact__c, pandadoc__Lead__c (Lookups) – These fields are populated when the document is created from the respective objects. Additionally, pandadoc__Account__c is populated when the document is created from an Opportunity, storing the Opportunity’s parent account.
  • pandadoc__ParentId__c (Formula, Text) – Contains the ID of the record from which the document was created. This field can be used to get the parent record ID when the document is created from objects other than Opportunity, Account, Contact, or Lead.
  • pandadoc__Template_Id__c (Text) – Contains the document’s template ID.
  • pandadoc__Template_Name__c (Text) – Contains the document’s template name. While this can be used for reporting, we recommend using pandadoc__Template_Id__c for conditions, as the template name can be changed later.
  • pandadoc__Is_Deleted__c (Checkbox) – Becomes True when the document is deleted in PandaDoc.
  • pandadoc__Status__c (Text) – Contains the current document status. Available document statuses can be found here.
  • pandadoc__UUID__c (Text) – ID of the document in PandaDoc.