+ Start a Discussion
ritikaritika 

how to check duplicate record insertion through visual force page?

hi
I  m inserting  new records (account ) through visual force page
but duplicate records are also getting inserted . How can i keep a
check on the insetion of duplicate records.Please guide if anybody
 has idea on this
 
Thanks
Swati
MiddhaMiddha
Hi Swati,

If you are using a custom controller, you can write your logic to check duplicates in you class and if you are using a standard controller, you can write a trigger which checks for duplicates while inserting a record. A sample trigger code is given for leads in Force.com Cookbook.

GreatG
dchasmandchasman
I would recommend using an apex code trigger regardless of controller technology you are using. Constraints like uniqueness checks really belong in your model layer to insure that they are always enforced regardless of the user interface layer or API used to modify or create data etc...
ClaiborneClaiborne
When inserting the record, do you have a unique field? If so, you could designate a field in the account record as an external ID. Then use the Upsert operation instead of Insert. If the external ID matches an existing record, the existing record id updated.

Also, how do you know you have a duplicate - matching email? matching name? matching company?