+ Start a Discussion

Checking for duplicate Opportunity Line Items

I am trying to find the best approach to find out if an Opportunity Line Item is a 'duplicate' based on the Product Name on the line item as well as a few fields on the Opportunity record itself, maybe Client Name, Business Unit and Sales Stage.

My thoughts are to use an after insert trigger to determine which fields need to be grabbed to 'lookup' exsiting opportunities and opportunity line items that might be duplicates, but I am stuck on how to do the code and then bulkify the code.  What type of collections(s) should the key fields be placed in so that we can query the database to look for potential duplicates?  If this is not the correct approach, please let me know.

Any suggestions?

Ramon PereiraRamon Pereira

Via the trigger also, however, do the following:

1. Create a field as ID on your opportunityLineItens object.
2- Create a workflow to copy the values (each time the record is created or edited) that you want identified which the record as a duplicate. Example:
Opportunity Id Code + Product + line item + other fields as their business rule.

As the field is ID, the salesforce will not accept that you insert a duplicate record.

Ensure that this approach solves your problem, if yes, mark it as resolved. If not, we will do via trigger.