This article will show you how to create a PDF quote and to send an email with an attachment in the record-triggered flow.
*The feature to create PDF that can be called up in a record-triggered flow is available in Office File Creator Pro.
- Process Overview
- Overall Flow
- Key Points for Flow Creation
- Create the Flow
- Create Resources
- 1. Get Price Book
- 2. Get Price Book Entry
- 3. Update Case (Quote)
- 4. Amount is 0?
- 4e. Update Case (Amount Error)
- 5. OFC – Save as PDF
- 6. OFC is Error?
- 6e. Update Case (PDF Creation Error)
- 7. Get Email Template
- 8. Sent Email with Quote
- 8e. Update Case (Send Email Error)
- 9. Update Case (Completed)
- Debug
- Reference
Process Overview
Process
- When a new case for a request for quotation is created, retrieve the price of the product code from the Price Book and update the quotation info, such as the Amount.
- Create the PDF Quote by the OFC action and send the email with the attachment to the Contact.
Prerequisite
- When a new case is created, the Contact is set automatically to match the email address in the Contact record.
- The email template is used when sending emails from the flow, and it has been created.
- The Template file and OFC_Template record have been created for the PDF Quote.
- Custom fields ProductName__c, ProductCode__c, Quantity__c, UnitPrice__c, SubTotal__c, SalesTax__c, Amount__c, QuoteDate__c, SendEmailDateTime__c, and ErrorDetails__c have been created in the Case.
Overall Flow
This is the overall picture of the flow.
Get the Price Book record.
2. Get Price Book Entry
Get the Price Book Entry record.
3. Update Case (Quote)
Update the quote info, such as Amount from the Price Book Entry.
4. Amount is 0?
Decide if the amount is 0. If the amount is 0, go to 4e. If the amount is not 0, go to 5.
4e. Update Case (Amount Error)
Update the Case status to "Amount Error" and exit the flow.
5. OFC – Save as PDF
Call the "OFC - Save as PDF" action and save the PDF quote as an attachment to the case.
6. OFC is Error?
Decide the error from the result of the OFC action. If error, go to 6e. If successful, go to 7.
6e. Update Case (PDF Creation Error)
Update the Case status to "PDF Creation Error" and exit the flow.
7. Get Email Template
Get the Email Template for the sending email for the quote.
8. Sent Email with Quote
Call the "Send email" action and send the email with the PDF quote to the Contact of the Case. If there is a failure in flow, go to 8e. If there is no failure, go to 9.
8e. Update Case (Send Email Error)
Update the Case status to "Send Email Error" and exit the flow.
9. Update Case (Completed)
Update the Case status to "Completed" and exit the flow.
Key Points for Flow Creation
- Fields used for merge fields of the PDF are updated with "Run Immediately". PDF creation and sending an email are executed with "Execute Asynchronously".
- To create a PDF Quote, call the "OFC - Save as PDF" action of OFC. After the action is executed, the result (success or failure) is retrieved and an error message is returned in case of failure.
- Attachment mail sending is sent from the mail sending action of the flow. Set the attachment Id to the contentVersionId obtained as a result of the OFC action.
Create the Flow
Open Flows from Setup and click the "New Flow" button.
Select "Start From Scratch" and click the "Next" button.
Select "Record-Triggered Flow" and click the "Create" button.
Set the Start.
Object: Case
Trigger the Flow When: A record is created
Condition Requirements: All Conditions Are Met (AND)
Field: Origin Operator: Equals Value: Web (Request for Quote)
Field: SendEmailDateTime__c Operator: Is Null Value: {!$GlobalConstant.True}
Select "Actions and Related Records" and check the "Include a Run Asynchronously path to access an external system after the original transaction for the triggering record is successfully committed".
Save the flow. Click the "Save" button.
Save the Flow under any name.
Flow Label: Send Email with Quote
Flow API Name: Send_Email_with_Quote
Create Resources
Click the "Toggle Toolbox" button in the upper left corner of the screen, then click the "New Resource" button.
Resource Type: Variable
API Name |
Data Type |
Decimal Places |
varProductName |
Text |
|
varUnitPrice |
Currency |
0 |
Resource Type: Formula
API Name |
Data Type |
Decimal Places |
Formula |
fmlSubtotal |
Currency |
0 |
{!varUnitPrice} * {!$Record.Quantity__c} |
fmlSalesTax |
Currency |
0 |
ROUND({!varUnitPrice} * 0.1, 0) |
fmlAmount |
Currency |
0 |
{!fmlSubtotal} + {!fmlSalesTax} |
1. Get Price Book
Click the "+" mark under "Run Immediately " and select "Get Records".
Set the properties.
Label: Get Price Book
API Name: Get_Price_Book
Object: Price Book
Condition Requirements: All Conditions Are Met (AND)
Field: Name Operator: Equals Value: Price Book (Customer)
Sort Order: Not Sorted
How Many Records to Store: Only the first record
How to Store Record Data: Automatically store all fields
2. Get Price Book Entry
Click the "+" mark under "Get Price Book" and select "Get Records".
Set the properties.
Label: Get Price Book Entry
API Name: Get_Price_Book_Entry
Object: Price Book Entry
Condition Requirements: All Conditions Are Met (AND)
Field: ProductCode Operator: Equals Value: {!$Record.ProductCode__c}
Field: Pricebook2Id Operator: Equals Value: {!Get_Price_Book.Id}
Sort Order: Not Sorted
How Many Records to Store: Only the first record
How to Store Record Data: Choose fields and assign variables (advanced)
Where to Store Field Values: In separate variables
Field: Name Variable: {!varProductName}
Field: UnitPrice Variable: {!varUnitPrice}
3. Update Case (Quote)
Click the "+" mark under "Get Price Book Entry" and select "Update Triggering Record".
Set the properties.
Label: Update Case (Quote)
API Name: Update_Case_Quote
How to Find Records to Update and Set Their Values: Use the case record that triggered the flow
Condition Requirements to Update Record: None – Always Update Record
Field: Amount__c Value: {!fmlAmount}
Field: ProductName__c Value: {!varProductName}
Field: QuoteDate__c Value: {!$Flow.CurrentDate}
Field: SalesTax__c Value: {!fmlSalesTax}
Field: Subtotal__c Value: {!fmlSubtotal}
Field: UnitPrice__c Value: {!varUnitPrice}
4. Amount is 0?
Click the "+" mark under "Run Asynchronously" and select "Decision".
Set the properties.
Label: Amount is 0?
API Name: Amount_is_0
Label: 0
Outcome API Name: Amount_is_0_Yes
Condition Requirements to Execute Outcome: Any Condition Is Met (OR)
Resource: {!$Record.Amount__c} Operator: Less Than or Equal Value: 0
Resource: {!$Record.Amount__c} Operator: Is Null Value: {!$GlobalConstant.True}
Click "Default Outcome" in the left sidebar.
Set the properties.
Label: Not 0
4e. Update Case (Amount Error)
Click the "+" mark under "0" and select "Update Triggering Record".
Set the properties.
Label: Update Case (Amount Error)
API Name: Update_Case_Amount_Error
How to Find Records to Update and Set Their Values: Use the case record that triggered the flow
Condition Requirements to Update Record: None – Always Update Record
Field: ErrorDetails__c Value: The amount is 0.
Field: Status Value: Amount Error
Click the "+" mark under "Update Case (Amount Error)" and select "End".
5. OFC – Save as PDF
Click the "+" mark under "Not 0" and select "Action".
Enter "OFC" in the search box, and select "OFC – Save as PDF".
Set the properties.
Lable: OFC - Save as PDF
API Name: OFC_Save_as_PDF
execution name: Send Email with Quote Flow
recordId: {!$Record.Id}
template: CaseQuote *OFC_Template for PDF Quote
6. OFC is Error?
Click the "+" mark under "OFC – Save as PDF" and select "Decision".
Set the properties.
Label: OFC is Error?
API Name: OFC_is_Error
Label: Error
Outcome API Name: OFC_is_Error_Error
Condition Requirements to Execute Outcome: All Conditions Are Met (AND)
Resource: {!OFC_Save_as_PDF.isSuccess} Operator: Equals Value: {!$GlobalConstant.False}
Click "Default Outcome" in the left sidebar.
Set the properties.
Label: Success
6e. Update Case (PDF Creation Error)
Click the "+" mark under "Error" and select "Update Triggering Record".
Set the properties.
Label: Update Case (PDF Creation Error)
API Name: Update_Case_PDF_Creation_Error
How to Find Records to Update and Set Their Values: Use the case record that triggered the flow
Condition Requirements to Update Record: None – Always Update Record
Field: ErrorDetails__c Value: {!OFC_Save_as_PDF.errorMessage}
Field: Status Value: PDF Creation Error
7. Get Email Template
Click the "+" mark under "Update Case (PDF Creation Error)" and select "End".
Click the "+" mark under "Success" and select "Get Records".
Set the properties.
Label: Get Email Template
API Name: Get_Email_Template
Object: Email Template
Condition Requirements: All Conditions Are Met (AND)
Field: DeveloperName Operator: Equals Value: SendQuoteEmail
Sort Order: Not Sorted
How Many Records to Store: Only the first record
How to Store Record Data: Automatically store all fields
8. Sent Email with Quote
Click the "+" mark under "Get Email Template" and select "Action".
Enter "Email" in the search box, and select "Send Email".
Set the properties.
Label: Send Email with Quote
API Name: Send_Email_with_Quote
Attachment ID: {!OFC_Save_as_PDF.contentVersionId}
Email Template ID: {!Get_Email_Template.Id}
Log Email on Send: {!$GlobalConstant.True}
Recipient Id: {!$Record.ContactId}
Related Record ID: {!$Record.Id}
Sender Email Address: Org email address *In this sample, the sender is the organization's email address.
Sender Type: OrgWideEmailAddress *In this sample, the sender is the organization's email address.
8e. Update Case (Send Email Error)
Click the "Send Email with Quote", and select "Add Fault Path".
Click the "+" mark under "Fault" and select "Update Triggering Record".
Set the properties.
Label: Update Case (Send Email Error)
API Name: Update_Case_Send_Email_Error
How to Find Records to Update and Set Their Values: Use the case record that triggered the flow
Condition Requirements to Update Record: None – Always Update Record
Field: ErrorDetails__c Value: {!$Flow.FaultMessage}
Field: Status Value: Send Email Error
9. Update Case (Completed)
Click the "+" mark under "Send Email with Quote" and select "Update Triggering Record".
Set the properties.
Label: Update Case (Completed)
API Name: Update_Case_Completed
How to Find Records to Update and Set Their Values: Use the case record that triggered the flow
Condition Requirements to Update Record: None – Always Update Record
Field: Status Value: Completed
Field: SendEmailDateTime__c Value: {!$Flow.CurrentDateTime}
The flow is complete. Click the "Save" button.
Debug
Only normal cases are described here. Check for other error cases as needed.
Create a Case record from the Records screen. Enter the necessary information for the flow, such as the Product Code, Quantity, and Contact.
Click the "Debug" button.
Here, only normal cases are described. Check other error cases as needed.
Path for Debug Run: Run Immediately
Debug Options: Skip start condition requirements
Case: Created Case
Ensure that the results of "Run Immediately" reach the end successfully.
From the Debug Details, verify that each result is correct.
Click the "Debug Again" button.
Path for Debug Run: Run Asynchronously
Debug Options: Skip start condition requirements
Case: Created Case
Ensure that the results of "Run Asynchronously" reach the end successfully.
From the Debug Details, verify that each result is correct.
After debugging is complete, click the "Activate" Button.
Reference
Use in Record-Triggered Flow (PDF)