Last Updated on April 23, 2022 by Rakesh Gupta
The last thing you want your Sales teams to do is to get ensnared in manual – or procedural – activities; they are your horsepower, free them up to do what they do best – Sell! Does that mean activities – not directly related to selling – can be eschewed? Far from it!
Let us have our cake and eat it too – think automation!!
Multiple research affirms the positive impact of automation on the bottom line! By leveraging automation, we can ensure that activities – not directly related to sales – get done without burdening your sales team.
Let us take a simple use case – generating a quote PDF whenever a customer is ready to receive a formal proposal containing the most current pricing information and product quantities. To generate a quote pdf should not require salespeople to click a button! And, thanks to Salesforce Flow, we can make that a reality!
Objectives:
After reading this blog, you’ll be able to:
- Understand what a Quote is
- Use filters and conditions to design a flow
- Understand the Apex callout process in Salesforce Flow
Business Use case
Martin Jones is a System Administrator at Gurukul on Cloud (GoC). He received a requirement to auto-generate a quote pdf whenever a quote gets created (only if Opportunity amount is greater than 0) so that salespeople can spend less time in Salesforce and more time selling.
What is a Quote?
A quote is a detailed list – of products or services with prices, shipping and billing addresses, payment terms and taxes, etc. – that is sent by a seller to a prospective buyer. Quotes usually have different statuses (Draft, In Review, Presented, Approved, Rejected, or Cancelled) depending on the stage of the sales process.
As of Winter’22 release, salespeople had to manually generate a quote pdf by clicking on the Generate PDF button. We can do better than that as automation champions – let us automate this process.
Automation Champion Approach (I-do):
Usually, with Salesforce, multiple approaches are available to solve a business requirement. Choose the ones that are simple, straight forward, and consume fewer resources.
Similarly in this scenario, either use Apex trigger or a combination of Flow and Process Builder.
Let us solve this scenario using After-save Record-Triggered Flow and Apex – as this business case involves generating PDF out of a quote record. Check out this article to understand why we are using after-save record-triggered flow for this scenario.
Before discussing the solution, 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.
Guided Practice (We-do):
There are 3 steps to solve Martin’s business requirement using After-save Record-Triggered Flow. We must:
- creating a custom label to store Quote Template Id
- Create Apex class & Test class
- Salesforce flow
- Define flow properties for record-triggered flow
- Create a formula to determine whether the quote record is new or old
- Add a decision element to check if the opportunity amount is greater than $0
- Add action – call an Apex class to generate a quote pdf
Step 1: Creating a Custom Label
- Click Setup.
- In the User Interface, type Custome Labels.
- Click on the New Custom Label button.
- Enter Short Description the Name will auto-populate.
- Now enter the Quote Template Id in the Value.
- Click Save
Step 2: Create an Apex class and Test class
- Click Setup.
- In the Quick Find box, type Apex Classes.
- Clicks on the New button.
- Copy code from GitHub and paste it into your Apex Class.
- Click Save.
Repeat the above steps and click the Test class. You can get the code from my GitHub repo.
Step 3.1: Salesforce Flow – Define Flow Properties
- Click Setup.
- In the Quick Find box, type Flows.
- Select Flows then click on the New Flow.
- Select the Record-Triggered Flow option and click on Next and configure the flow as follows:
- How do you want to start building: Freeform
- Object: Quote
- Trigger the Flow When: A record is created or updated
- Set Entry Criteria
- Condition Requirements: None
- Optimize the Flow For: Action and Related Records
- Click Done.
Tips: Never try to write entry criteria in a Record-Triggered Flow.
Step 3.2: Salesforce Flow – Formula to Determine Whether the Quote Record is New or Old
- Under Toolbox, select Manager, then click New Resource to determine whether the record is new or old
- Input the following information:
- Resource Type: Formula
- API Name: forBIsNew
- Data Type: Boolean
- Formula: IsNew()
- Click Done.
Step 3.3: Salesforce Flow – Using Decision Element to Check the Opportunity Amount
Now we will use the Decision element to check the opportunity amount to ensure that it is greater than $0.
- Under Toolbox, select Element.
- Drag-and-drop Decision element onto the Flow designer.
- Enter a name in the Label field; the API Name will auto-populate.
- Under Outcome Details, enter the Label the API Name will auto-populate.
- Condition Requirements to Execute Outcome: All Conditions Are Met (AND)
- Row 1:
- Resource: {!$Record.OpportunityId}
- Operator: Is Null
- Value: {!$GlobalConstant.False}
- Add Condition
- Row 2:
- Resource: {!$Record.Opportunity.Amount}
- Operator: Greater Than
- Value: 0
- Add Condition
- Row 2:
- Resource: {!forBIsNew}
- Operator: Equals
- Value: {!$GlobalConstant.True}
- Row 1:
- Click Done.
Step 3.4: Salesforce Flow – Adding an Action to Call Apex class to Generate Quote PDF
- Under Toolbox, select Element.
- Drag-and-drop the Actions element onto the Flow designer.
- Select the GenerateQuotePdfDocument Apex class.
- Enter a name in the Label field- the API Name will auto-populate.
- Set Input Values:
- Field: quoteIds
- Value: {!$Record.Id}
- Click Done.
In the end, Martin’s Flow will look like the following screenshot (I turned on Auto-Layout) for this flow:
Once everything looks good, perform the steps below:
- Click Save.
- Enter Flow Label the API Name will auto-populate.
- Click Show Advanced.
- API Version for Running the Flow: 53
- Interview Label: Record-Trigger: Quote After Save {!$Flow.CurrentDateTime}
- Click Save.
Almost there! Once everything looks good, click the Activate.
It’s time to test this feature!
Next time, when a Sales rep creates a quote and associates it with Opportunity (obviously Opportunity amount must be greater than 0) then, then Salesforce Flow will fire and auto-generate a quote pdf for it.
Great! You are done! Feel free to modify it based on your business requirement.
Formative Assessment:
I want to hear from you!
What did you learn from this post, is it relevant to you, and how will you modify the concepts taught in the post for your own business processes?
Make a post and tag me on Twitter @automationchamp using #AutomationChampionFlow.








Hi Rakesh, The code works perfectly PDF is generating correctly.
But Quote line items are missing in the PDF, could you let me know why Quote line items are missing in the PDF.
For anyone looking to use this for more than one template…. create a Custom Label for each Quote Template and name accordingly. Ex: QuoteTemplateIDQuarterly, QuoteTemplateIDAnnual). Then create an Apex Code for each as well and again label accordingly (line 1 of code “generateQuotePDFDocumentQuarterly” or “generateQuotePDFDocumentAnnual”) then update the Name of the template you wish to use in the code Line 15 Example: Label.QuoteTemplateID > Label.QuoteTemplateIDSubscription.
I hope this helps others that need to use it for more than one template. 🙂
Thank you!