function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
JSchneiderJSchneider 

Copy QuoteLineItems, then delete original QuoteLineItems - Flow

This should be easy, but I've got the Salesforce Admin version of writers block.

I am looking to create a headless flow that takes my QuoteLineItems from a Quote and creates new QuoteLineItems in the exact same SortOrder on the exact same quote.  Then I want it to delete the original set of QuoteLineItems.
Best Answer chosen by JSchneider
JSchneiderJSchneider
The reason I was trying to accomplish this was so that my QuoteLineItem Numbers were sequential in the Sort Order I had established.  When pulling QuoteLineItems into a Visualforce Page, they were being sorted based on the Number and there was no way to alter it to the Sort Order.

In case anyone needs to know how I ended up building this.
  1. Fast Lookup of QuoteLineItems matching on QuoteId.  Sort results by Sort Order Ascending. Store results in a SObject Collection Variable.
  2. Loop through the Collection, loop variable is SObject Variable set for QuoteLineItems.
  3. Assignment.  SObject Variable for New QuoteLineItems.  Fields are set equal to the corresponding field from QuoteLineItem SObject Variable.
  4. Assignment.  NewQuoteLineItems are added to a new SObject Collection Variable (records to create). Flow back to loop.
  5. Fast Delete.  Original SObject Collection of Quote Line Items.
  6. Fast Create.  Second SObject Collection on New Quote Line Items.
I have noticed however that though it creates the new set of line items in order based upon the original Sort Order, the Sort Order for the new items is not the same.