You need to sign in to do that
Don't have an account?

help on trigger two records are inserted instead of one..???
trigger test on Lead (after insert)
{
Set<ID> ls = new Set<ID> ();
for(Lead l:Trigger.new)
{
ls.add(l.id);
}
List <Lead> lis=[Select Id,Name,Status,Email,Company,fax,FirstName,LastName from Lead where id in:ls];
List<Contact> con=[Select Id,Name ,Email_2__c,fax from Contact ];
List<Contact> lstContact = new List<Contact>();
//List<Contact> cntem=[Select Id,Email_2__c from Contact where Email_2__c=:lis.Email];
for(Lead ld:lis)
{
for(Contact cn:con)
{
if(ld.Email==cn.Email_2__c)
{
//Trigger.new[0].addError('Email already exists');
}
else if(ld.Email != cn.Email_2__c)
{
Contact objC= new Contact();
objC.FirstName=ld.FirstName;
objC.LastName=ld.LastName;
objC.RecordTypeName__c='Candidates';
lstContact.add(objC);
}
if(lstContact.size() > 0 )
insert lstContact;
}
My problem is when i insert a lead...2 contacts are inserted instead of one...can some tell me why this is happening...pl help...
It looks you are trying to create a contact when lead is inserted with validation on Email field
Below is trigger script for you, This will works for bulk data upload as well .
Thanks,
bForce
All Answers
It looks you are trying to create a contact when lead is inserted with validation on Email field
Below is trigger script for you, This will works for bulk data upload as well .
Thanks,
bForce
Thanks b-Force.It works for me...thanks
:):)