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
Rohit Singh 32Rohit Singh 32 

HI I want to write trigger to prevent duplicates entry of account and unique field is email..please tell me what is the pseudo for it.

JayantJayant
Two ways to do it - 
1. Trigger - Write a Before Insert or After Insert trigger and query for Accounts with same email. In before, if you get any record, add error. In after, if you get more than 1 record, add error.
2. If Email is custom field, simply mark it as unique. If it's a standard field, create a custom text field and mark it as unique. Add a workflow field update to copy the Email field's value to this Custom field. You are done.
Thiyagarajan Selvaraj (SFDC Developer)Thiyagarajan Selvaraj (SFDC Developer)
Hi Rohit,

You can also acheive this without writing any code. You can use duplicate management in salesforce - create matching and duplicate rules on account object. 

Refer this : https://help.salesforce.com/apex/HTViewHelpDoc?id=managing_duplicates_overview.htm