Friday, 24 October 2014

How to write a DeDuping for Lead or Contact Object.

In this scenario to avoid duplicate email in Lead or Contact object.



I have two object one is standard object and another one is custom object here my question is I am create a new record standard or custom its clone of another record. How u can implements this one.


trigger CloneRecOnAccount on Account (after insert) 
{
list<Account> setAccList = new list<Account>();
set<string> accNameSet = new set<string>();
for(Account newAcc : Trigger.new)
{
accNameSet.add(newAcc.name);
}

list<Account> getAccRec = [ select name,TimeStamp__c from Account where name in : accNameSet];

for(Account getAcc : Trigger.new )
{
if(getAccRec.size() < 2)
{
Account acc = new Account();
acc.name = getAcc.name;
acc.TimeStamp__c = getAcc.TimeStamp__c;
setAccList.add(acc);
}
}
insert setAccList;
}