Skip to main content

Hi Experts,

I have a functionality, where I donot want users to provide duplicate Email associated with Account. The below triggers works perfectly. If there ate 100K Account records are present in the SalesForce System, then will the below triggers work?

 

/* Preventing users creation of duplicate in Salesforce*/

trigger PreventDuplicateNameAccount on Account (before insert, before update) {

//Preparing Account names in Set from trigger.new

Set<String> nameSet = new Set<String>();

for(Account acc : trigger.new){

nameSet.add(acc.Email__c);

}

// getting the list of accounts in database with the account name we entered ( trigger.new)

List<Account> accList = new List<Account>(

[select id,name, Email__c from Account where Email__c in: nameSet]);

for(Account a : trigger.new){

if(accList.size() > 0 )

a.addError('Accounts Email already exists in your Organization with Email '+a.Email__c);

}

}

 
3 个回答