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
Mani SampathkumarMani Sampathkumar 

Flow creates duplicate Pricebook records

I am facing a strange issue in flows. I have created a flow which will create Pricebook, Product and Pricebookentry records. This flow is triggered when a flag is checked on the custom object, lets say X. This works fine when I update the flag manually on X, but when I run a bulk update, flow creates duplicate pricebook records though it should not as the first step in the flow should identify the existing pricebook (based on the account name in X object) and it should proceed to Create product step. Has anyone faced this issue or am I missing something here? Thanks in advance!

User-added image
Mani SampathkumarMani Sampathkumar
Just to reiterate, Suppose, X object has 2 records and for which the account is same, when the flag is updated manually for the 1st and 2nd record, system creates 1 pricebook(name as same as account name), 2 products and pricebook entry records. Let's say if I update the 2 X records, system creates 2 pricebook records instead of one. Please note that flow is triggered through a process.
Mani SampathkumarMani Sampathkumar
Can someone help me on this pls?
ShashankShashank (Salesforce Developers) 
Hi,

You might  want to replicate the same using Process Builder and see if you are still facing this issue.

Thanks,
Shashank
​Salesforce
Mani SampathkumarMani Sampathkumar
Hi,

Thanks for your response.
No worries, I found a workaround by extracting the accounts which has more than one Rate Card(X object as per my earlier comments). From the list, make sure that I extracted Rate Card records which has unique account ids and update the flag.  System created Pricebook, Products and Pricebook Entry as expected without any duplicates.Then, updated the flag for the rest of the records and system created Pricebook, Products and Pricebook Entry records for the remaining Rate Card records.

Regards
Mani
Mani SampathkumarMani Sampathkumar
Hi Shashank,

Just to add on my earlier comment, I didn't try process Builder for creating Pricebook, Product and Pricebook Entry because I want to query Pricebook before creating it which I think is not possible.

Regards
Mani
SF ABCSF ABC
Hi Mani,

Just saw the post.
I encountered the similar issue but it seems your workaround won't work if the update / insert is automatic.
My workaround is:
- Create two flows:
  Deal_with_Existing_Phonebook_Flow
  Deal_with_Not_Existing_Phonebook_Flow

- Deal_with_Existing_Phonebook_Flow won't create "pricebook", just take the path of "skip pricebook". It is a clone of your flow without the element of "Create Pricebook". Ie, the flow will only deal with records that have existing pricebook.  The records that don't have existing pricebook will be ignored. The flow can be run at the batch size up to 200.

- Deal_with_Not_Existing_Phonebook_Flow is just the same as your current flow. The input of the flow are the records that don't have existing pricebook. Batch size is set as 1 to avoid duplicates. Operation is upsert.  Alternatively, you can also use a lookup element in the beginning of the flow to get the list of the records that don't have existing pricebook then loop through each record.