Auto Create and Activate a Contract

Auto Create and Activate a Contract

Last Updated on February 16, 2022 by Rakesh Gupta

Big Idea or Enduring Question:

How do you create and activate a contract using Salesforce Flow?

Objectives:

After reading this blog post, the reader will be able to:

  • Use After-save Record-Triggered Flow to create a draft contract
  • Use a Decision element to check field values
  • Use the Update Records element to activate a contract
  • and much more 

Business Use case

Tamara McCleary is working as a System Administrator at Universal Containers (UC). At UC they are using Salesforce to manage their Contracts. Salesforce allows you to create a Contract for an Account. Whenever an Opportunity is successfully closed (Stage: – Closed Won), auto-create a new Contract and activate it. Also, set the following fields

  • Contract Start Date = Close date of current Opportunity
  • Contract Term (months) = 12.

Automation Champion Approach (I-do):

There are multiple ways to solve the above business requirement. You can either use Apex trigger, a Combination of Flow & Process Builder, and more. To solve this requirement, we will use Salesforce Flow.  Before starting the implementation,  you need to understand a few things:

  • Contract management is the management of contracts made with customers, vendors, or partners. Salesforce also allows you to manage contracts.
  • Salesforce doesn’t allow you to insert a Contract with Status = Activated (Either through Data Loader, Workflow Rule, Process Builder, or Flow), if you attempt to do so, you will get an error. In other words, it is not possible to create and activate Contracts in a single step. Contracts must first be added with a Status of Draft, and then after inserting, they can then be updated with a status of Activated.

This article helps you to understand how to auto-create and activate a contract using Salesforce Flow, which will only fire Whenever a record is created, and any time it’s edited to subsequently meet criteria

To solve this requirement, we will use the After-save Record-Triggered Flow. Check out this article to understand why we are using after-save record-triggered flow for this scenario.

Before discussing it, let me show you a diagram of a Process Flow at a high level. Please spend a few minutes going through the following Flow diagram and understand it. Let’s begin building this automation process. Follow the instructions below to create a Flow that meets the business requirement.

Guided Practice (We-do):

There are 4 steps to solve Tamara’s business requirement using Salesforce Flow. We must:

  1. Define Flow properties for record-triggered flow
  2. Add a Decision element to check the opportunity stage and account
  3. Add a Create Records element to create a contract with draft status 
  4. Add an Update Records element to activate a contract 

Step 1: Salesforce Flow – Define Flow Properties

  1. Click Setup.
  2. In the Quick Find box, type Flows.
  3. Select Flows then click on the New Flow.
  4. Select the Record-Triggered Flow option, and click on Create and configure the flow as follows:
    1. Object: Opportunity
    2. Trigger the Flow When: A record is created or updated
    3. Set Entry Criteria
      1. Condition Requirements: None
    4. Optimize the Flow For Action and Related Records
  5. Click Done.

Step 2: Salesforce Flow – Using Decision Element to Check Opportunity Stage and Account

Now we will use the Decision element to check the stage to ensure that it is equal to Closed Won and the Account is associated with the opportunity.

  1. On Flow Designer, click on the + icon and select the Decision element.
  2. Enter a name in the Label field; the API Name will auto-populate.
  3. Under Outcome Details, enter the Label the API Name will auto-populate.
  4. Condition Requirements to Execute Outcome: All Conditions Are Met (AND)
    1. Row 1:
      1. Resource: {!$Record.StageName}
      2. Operator: Equals
      3. Value: Closed Won
    2. Click Add Condition
    3. Row 2:
      1. Resource: {!$Record.AccountId}
      2. Operator: Is Null
      3. Value: {!$GlobalConstant.False}
    4. When to Execute Outcome: Only if the record that triggered the flow to run is updated to meet the condition requirements
  5. Click Done.

The reason why we would select the – Only if the record that triggered the flow to run is updated to meet the condition requirements checkbox — is to allow the Salesforce Flow to execute the actions only if the record meets the criteria now, but the values that the record had immediately before it was saved didn’t meet the criteria. This means that these actions won’t be executed when irrelevant changes are made.

Step 3: Add Action – Create a Record Element to Create a Contract with Draft Status 

The next step is to create a record contract in draft status. For this, we will use the Create Records element. Now follow the steps below:

  1. On Flow Designer, click on the + icon and select Created Records element.
  2. Input the following information:
    1. Enter Label the API Name will auto-populate.
    2. How Many Records to Create: One
    3. How to Set the Record Fields: Use separate resources, and literal values
    4. Object: Contract
    5. Set Field Values for the Contract
      1. Row 1:
        1. Field: AccountId
        2. Value: {!$Record.AccountId}
      2. Click Add Row
      3. Row 2:
        1. Field: ContractTerm
        2. Value: 12
      4. Click Add Row
      5. Row 3:
        1. Field: StartDate
        2. Value: {!$Record.CloseDate}
      6. Click Add Row
      7. Row 4:
        1. Field: Status
        2. Value: Draft
  3. Click Save.

Step 4: Salesforce Flow – Add an Update Records Element to Activate a Contract

The next step is to activate the contract.  For this, we will use an Update Records element.

  1. On Flow Designer, click on the + icon and select the Update Records element.
  2. Enter a name in the Label field; the API Name will auto-populate.
  3. Click Specify conditions to identify records, and set fields individually
  4. Object: Contract
  5. Select All Conditions Are Met (AND)
  6. Set Filter Conditions
    1. Row 1:
      1. Field: Id
      2. Operator: Equals
      3. Value: {!Create_a_Draft_Contract}
  7. Set Field Values for the Case Records
    1. Row 1:
      1. Field: Status
      2. Value: Activated
  8. Click Done.

  In the end, Tamar’s Flow will look like the following screenshot: Once everything looks good, perform the steps below:

  1. Click Save.
  2. Enter Flow Label the API Name will auto-populate.
  3. Click Show Advanced.
  4. API Version for Running the Flow: 54
  5. Interview Label: Record-Trigger: Record-Triggered Flow: Opportunity After Save {!$Flow.CurrentDateTime}
  6. Click Save.

Almost there! Once everything looks good, click the Activate.

Proof of Concept

Now onwards if a business user updates the Opportunity Status to Closed Won, Salesforce Flow will automatically create a new Contract and activate it. It’s time to test out the process.

  1. Existing Opportunity – Stage Qualification
    1. Currently, Opportunity “Edge Emergency Generator” is in the Qualification Stage.
  2. Opportunity Stage After Update
    1. Now we will try to update the Opportunity “Edge Emergency Generator” Stage to Closed Won.
  3. New Contract (Status – Activated)
    1. Once you are done, click on the Save button and check the Contract created by Salesforce Flow.

Formative Assessment:

I want to hear from you!  

What is one thing you learned from this post? How do you envision applying this new knowledge in the real world? 

Let me know by Tweeting me at @automationchamp, or find me on LinkedIn.

Have feedback, suggestions for posts, or need more information about Salesforce online training offered by me? Say hello, and leave a message!

11 thoughts on “Auto Create and Activate a Contract

  1. Hi Rakesh is it not possible to place contract activation logic in another action instead of creating a new process?
    Once contract record is created in Draft , in another action we can activate it right??

      1. Hi Rakesh,

        I have made a small change and try to figure out what we can do now in this scenario?

        I have merged both process builder. by creating one more action in first process.

        first time it works great when opportunity get closed won.[result = it create a contract and activate it]

        now what i did here => i cloned the contract and create 4 new contract with draft status.

        i changed the status field of same opportunity and again set to closed won.

        NOW I SURPRISED ==> all contracts get activated; [ I hope that only the newly created contract will get update]

        can you please help me if I want to update only the new contract then what should I do?

        1. I need some time to think – but the best possible solution is to use Flow – Where Record Lookup element will allow you to sort the record based on CreatedDate or any field.

  2. Thank you Rakesh, this was just about spot on for a process I needed to build out. If I wanted to go a bit further and have a Contract Payment record created for each month of the term is that something I can achieve with Process Builder as well?

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.