How To Use Flow to Number Quote Line Items Starting from One
Anna Szabo, JD, MBA
Prosci Certified Customer Success Manager | Golden Hoodie Award Recipient 29x Salesforce Certified | Worked on the Product Team at Salesforce with 19x Salesforce Partners | Digital Transformation Experience 10+ Years
If you need to number Quote Line Items starting from one, there are no native options in Salesforce Sales Cloud, only in CPQ. You can't use auto-number because the numbers will be assigned sequentially across all records on the object. When I tried this method, my line item one was numbered at 5,000 and also the numbering wouldn’t even show on quote PDF when it's generated.
BUSINESS REQUIREMENT
The actual business requirement from my client is for the numbers on Quote Line Item to start over for each quote: line item number one, two, three, etc. The numbers must recalculate as line items are removed or added. This will require Salesforce automation.
SOLUTION: RECORD-TRIGGERED FLOW
We are going to create a record-triggered flow on the Quote object and run it when record is created or updated.
CREATE RESOURCES
On the Quote object, create a Roll-Up Summary field called “Total Quote Line Items” that counts all related Quote Line Items. I added this to the page layout for my client to see in Quote details section how many?line items are on this specific quote (so they don't need to click in related tabs and figure this out).
On the Quote object, create a new “Quote Line Item Number” number field with zero decimal places. See below.
Each time a Quote Line Item is added to a Quote, we need to look at all associated line items and assign sequential numbers, based on the order in which they were added.?
Resources to create ??
VarQuoteId holds the Quote Id from the record that starts the Flow
VarOne holds the new Quote Line Item Number
SObject Collection Variable:
领英推荐
CREATE ACTIONS
"Get Quote Line Items" action
The first action is to get all the Quote Line Items for a specified Quote. This will be the first action of the Flow, connected from the Start element. It needs to look up all the Quote Line Item records where the Salesforce Quote ID equals the value in the “VarQuoteID” variable. We want the Line Item number applied when the Quote Line Item was added so this step is sorting by the Created Date in Ascending order. Check "all records" and "automatically store all fields."
"Loop" action
Now we want to loop through the collection of Quote Line Items we created by getting records, and examine one record at a time, then update each record's line item number. Drag a Loop element onto the canvas, and configure it so that it loops through the collection variable we had just created. Be sure to accept the default Direction of First item to Last item. But before we do, let's make sure the Quote actually does have Line Items. My colleague taught me to think through various scenarios and make sure we don't loop through "nothing." So, alway make sure there's a reason to loop: records do exist. Then, examine the {!Get_Quote_Line_Items} collection of pulled records to number them.
"First Assignment" action
Now we need to edit each record in the Loop. Drag an Assignment element onto the canvas. Name it "Assign Quote Line Item Number." For Variable, first, select “Current Item from Loop" and select the custom field we previously created called "Quote_Line_Item_Number__c" in the list of Quote Line Item fields. Set the Operator to Equals, and for Value, select VarOne. On the first record processed in the loop, Line Number is set to VarOne’s default value of 1.?Your Assignment action should look as follows.
"Second Assignment" action
This action could have been a part of the first action, but keeping it separate provides better clarity on which action does what and when. The first assignment action helped us set the first Quote Line Item's number to “1,” which is the default in the VarOne variable. This next action will add "1" to the VarOne variable before the next record is processed. Let's call this "Increment Line Number." It also adds the record in the loop to CollUpdatedLineItems for the update action.?For value, select “Current Item from Loop” as shown.
"Update Records" action
After the loop has processed all of the Quote Line Item records in the collection of all pulled records, the flow is ready to mass update the records that have been added to CollUpdatedMembers. Drag the Update Records element onto the canvas, and select the CollUpdatedLineItems collection for record update. Select "Update Records."
RESULT
Here's the final flow.
Product architect in low code and process automation platforms with experience helping over 30 enterprises from startups to Fortune 500 to constantly innovate at lightning pace
1 年Thanks for the pointer, I would actually remove the Decision and just make sure the trigger only runs when Total Quote Line item is bigger than zero. Too bad when we try to use this quote line item number inside the out of the box quote template, the line items are not sorted nor can I change the sort settings.