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
Adil Al-HabibAdil Al-Habib 

Flow to create Work Order Line Item records from previous Work Order

User-added imageI am attempting to create a flow that will trigger when a work order is created with a specific criteria and create work order line item records that were under the previous work order.

So far I have done the following:
Get Records on the Work Order Line Item object based on the work order ID. I would store multiple records and automatically store all fields

Then I have created a loop through each record.

Inside the loop I create a record one by one using seperate rescources and literal values and set the values of the fields within that record.
 

What am I doing wrong?
 

Thanks in advance!

Nagarjuna ParalaNagarjuna Parala
Hi @Adil,
Thank you for reaching out to the community.

May I recommend you please add a list variable to store the record inside the loop and then use create records outside of the loop using the list variable?

I hope this will resolve your issue. Please do let me know if you need any further information on this.


Thanks & Regards'
Nagarjuna
 
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Adil,

As you are doing DML operation inside the For Loop it may cause issue. It is always recommended to do DML operation outside the for loop.

Create a variable of type record which accepts multiple variables and assign the records and outside the for loop create the record .

Please find the below example (https://www.salesforceben.com/salesforce-flow-loops-best-practices-and-examples/) for similar requirement.

Let me know if you face any issues.

If this solution helps, Please mark it as best answer.

Thanks,
Adil Al-HabibAdil Al-Habib
Thanks for your replies @Nagarjuna and @Sai. I have set an assignment to a single variable then assigned the single variable to the multiple record variable as suggsested, when I debug, I see that it did successfully retrieve the records mentioned but when it tried to create the child work order line item records under the current parent work order I recieve the error: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY: insufficient access rights on cross-reference id.

When I create a work order and add work order line items records manually I do not receive such an error.
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Adil,

Can you share the screenshots of each element of the flow so can check and let you know the issue.

Thanks,
 
Adil Al-HabibAdil Al-Habib
User-added imageUser-added imageUser-added imageUser-added imageUser-added image
Adil Al-HabibAdil Al-Habib
User-added image
Sai PraveenSai Praveen (Salesforce Developers) 
Hi,

The only issue in the flow which I feel is Your are assiging ProductId to the WOLI. Can you assign AssetId and also Workorderid is missing assignment(Assign Individual  WOLI) because of which you are getting .

Can you modify those and try again.

Let me know if you face any issues.

If this solution helps, Please mark it as best answer.

Thanks,
Adil Al-HabibAdil Al-Habib

Hi Sai,

We do not use Asset ID, we use the Pricebook Entry ID which has the label Product ID.

I added an additional assignment in the Assign Individual WOLI for:
 

WOLIRecord>Work Order ID to be equal the loop variable work order ID.

This time I didn't get an error but the process didn't work. The WOLI records were not created at all. Also during debugging I noticed 9 records were passed to the Create WOLI element when only 3 record were present. 

Sai PraveenSai Praveen (Salesforce Developers) 
Hi Adil,

If possible can we connect over and check excat issue so can try to resolve it.

Thanks,
 
Adil Al-HabibAdil Al-Habib
Hi Sai,

I can arrange that in my sandbox. Please reach out to me at amalhabib@lkqcorp.com
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Adil,

I cannot reach over email. I will keep eye on developer forum. If you need any help we can connect over gmeet .

Thanks,
 
Adil Al-HabibAdil Al-Habib
Thanks Sai. Please let me know how to connect over gmeet