+ Start a Discussion
Dan NorfleetDan Norfleet 

Process Builder / Work Flow / Apex Code - Best Solution?

We need to create a process that loops through an order once it has been submitted and determine if it has duplicate items.  If it does, we would delete the duplicate from the order automatically.  We are still learning from the tools available. When reading through the order items, we will match on the SKU / Category - if there is more than 1 occurrence within that order, we wish to delete the last occurence.

Haven't figured out how to do this yet in Work Flow / Process Builder.  Wondered if someone with more experience on the various options can give the best practice solution?

Thanks 

Dan
Best Answer chosen by Dan Norfleet
MagulanDuraipandianMagulanDuraipandian
Hi,
Have you tried Duplicate Rule?

check this - http://www.infallibletechie.com/2016/05/how-to-avoid-duplicate-in-custom-object.html

 Instead of deleting it, you can avoid creation of duplicate.

All Answers

MagulanDuraipandianMagulanDuraipandian
Hi,
Have you tried Duplicate Rule?

check this - http://www.infallibletechie.com/2016/05/how-to-avoid-duplicate-in-custom-object.html

 Instead of deleting it, you can avoid creation of duplicate.
This was selected as the best answer
Dan NorfleetDan Norfleet
Magulan, thanks so much.  Going to look into this as an option.  Appreciate the help :)

Dan
Dan NorfleetDan Norfleet
Magulan, i set up a the matching / duplicate rule.  Unfortunately, the visual force page where our users add items to a cart / order, does NOT execute the rule.  It allows us to still set up duplicate order / item records.  Do dup/matching rules work with Visual Force Pages?  Is there something else that needs to be enabled to get them to work?

Dan
MagulanDuraipandianMagulanDuraipandian
Dan,
Check this to handle in VF - https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_class_Datacloud_DuplicateResult.htm