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

How to send a email in trigger
Hi All i have a requirement like this an lead should be created once the lead created a contact should be created and lead should be deleted
1st part is working fine and for second part:
if we have exisitng contact with same email and an email should be sent for the user and it should be updates with exisitng contact
Can any one help with this :
Please see my code below :
trigger CreateContactTest on Lead (After Insert)
{
//Map<string,Id> mapaddress = New Map<String,Id>();
List<Lead> toDelete =New List<Lead>();
Set<string> Email= new Set<string>();
List<Contact>Contacts=[Select Id,Email from Contact Where Email=:Email];
List <Contact>Con= new List<Contact>();
For( Lead LD:Trigger.new)
{
Contact cc = New Contact();
cc.FirstName= LD.FirstName;
cc.LastName=LD.LastName;
// cc.Name=LD.Name;
cc.Salutation=LD.Salutation;
cc.Email=LD.Email;
cc.Title=LD.Title;
cc.Phone=LD.Phone;
Con.add(cc);
Todelete.Add(LD);
}
insert con;
if(todelete.size()>0)
Delete [Select ID from lead where Id In:ToDelete];
}
1st part is working fine and for second part:
if we have exisitng contact with same email and an email should be sent for the user and it should be updates with exisitng contact
Can any one help with this :
Please see my code below :
trigger CreateContactTest on Lead (After Insert)
{
//Map<string,Id> mapaddress = New Map<String,Id>();
List<Lead> toDelete =New List<Lead>();
Set<string> Email= new Set<string>();
List<Contact>Contacts=[Select Id,Email from Contact Where Email=:Email];
List <Contact>Con= new List<Contact>();
For( Lead LD:Trigger.new)
{
Contact cc = New Contact();
cc.FirstName= LD.FirstName;
cc.LastName=LD.LastName;
// cc.Name=LD.Name;
cc.Salutation=LD.Salutation;
cc.Email=LD.Email;
cc.Title=LD.Title;
cc.Phone=LD.Phone;
Con.add(cc);
Todelete.Add(LD);
}
insert con;
if(todelete.size()>0)
Delete [Select ID from lead where Id In:ToDelete];
}
Try with below code it wil help !! Let me know if it helps !!
Thanks
Manoj