Content Document Link Flows
Add Quote Files to Opportunity
Design
This is most commoonly used to copy a DocuSign file from a Quote to an Opportunity
As a Salesforce User
I want all files related to a Quote to be visible on the parent Opportunity
So that I can easily view the files from the Opportunity record without having to navigate to the Quote record
Given I am on a Quote record page
When I upload a file to the Quote
Then the file is visible on the parent Opportunity record
Build
At the time of writing in June 2024 Flows can NOT be triggered by Content Document Link creation, as a workaround you can use an Apex Trigger to call a Flow when a new Content Document Link is created
To-do:
- Create a Flow to update the Opportunity with the Content Document Link
- Create a Apex Trigger to call a flow when a new Content Document Link is created
Flow
Flow Type: Autolaunched Flow (No Trigger)
Flow Label: CDL: Add Quote CDL to Opp
Flow API Name: CDL_Add_Quote_CDL_to_Opp
Description: Updates the Opportunity with the Content Document Link from the Quote.
Recosource Type: Variable
API Name: recordId
Data Type: Text
available for input: checked
The recordID is the Id of the Content Document Link that was created and is being passed to the flow via the Apex Trigger.
- Element: Get Records
Label: Get Content Document Link
Object: Content Document Link
Conditions:- Id -> Equals ->
{!recordId}
- Id -> Equals ->
- Element: Decision
Label: Linked Entity is Quote?
Outcome 1:- Label: Yes - Quote
- Condition:
{!Get_Content_Document_Link.LinkedEntityId}
Starts With0Q0
Quotes have an Id that starts with0Q0
, this can be verified by checking the Id of a Quote record in the URL.
- Element: Get Records
Label: Get Quote
Object: Quote
Conditions:- Id -> Equals ->
{!Get_Content_Document_Link.LinkedEntityId}
- Id -> Equals ->
- Element: Create Records
Label: Create CDL for Opportunity
Object: Content Document Link
Set Field Values: - Linked Entity Id ={!Get_Quote.OpportunityId}
- Content Document Id ={!Get_Content_Document_Link.ContentDocumentId}
Create Apex Trigger
Apex Trigger can only be created in a Salesforce Developer Edition or a Salesforce Sandbox. It cannot be created in a Salesforce Production org.
Trigger Name: ContentDocumentLinkTrigger
Object: ContentDocumentLink
Trigger Code:
trigger ContentDocumentLinkTrigger on ContentDocumentLink (after insert) {
for (ContentDocumentLink cdl : Trigger.new) {
// Create a map to hold the flow inputs
Map<String, Object> flowInputs = new Map<String, Object>();
flowInputs.put('recordId', cdl.Id);
try {
// Create and start the flow interview
Flow.Interview.CDL_Add_Quote_CDL_to_Opp flowInterview = new Flow.Interview.CDL_Add_Quote_CDL_to_Opp(flowInputs);
flowInterview.start();
} catch (Exception e) {
System.debug('Exception: ' + e.getMessage());
}
}
}
Test
Steps
- Open a Quote record page
- Upload a file to the Quote
- Verify the file is visible on the parent Opportunity record
Expected Results
- The file is visible on the parent Opportunity record
Add Only DocuSign Files to Opportunity
This flow is a variation of the previous flow, it simply adds a DocuSign filter.
Design
As a Salesforce User
I want all DocuSign files related to a Quote to be visible on the parent Opportunity
So that I can easily view the DocuSign files from the Opportunity record without having to navigate to the Quote record
Given I am on a Quote record page
When I upload a DocuSign file to the Quote
Then the DocuSign file is visible on the parent Opportunity record
Build
Create a flow as shown above Content Document Link Flows
Amend the Decision element to check if the file is a DocuSign file
Element: Decision
Label: Linked Entity is Quote?
Outcome 1:
Label: Yes - Quote
Conditions:
{!Get_Content_Document_Link.LinkedEntityId}
-> Starts With ->0Q0
Quotes have an Id that starts with0Q0
, this can be verified by checking the Id of a Quote record in the URL.{!Get_Content_Document_Link.ContentDocument.Title}
-> Contains ->DocuSign
\
Test
Steps
- Open a Quote record page
- Upload a DocuSign file to the Quote
- Verify the DocuSign file is visible on the parent Opportunity record
- Upload a non-DocuSign file to the Quote
- Verify the non-DocuSign file is NOT visible on the parent Opportunity record
Expected Results
- The DocuSign file is visible on the parent Opportunity record
- The non-DocuSign file is NOT visible on the parent Opportunity record