+ Start a Discussion
kishore babu 20kishore babu 20 

create a lead record while inserting contact associated account using trigger?

Raj VakatiRaj Vakati
You can able to do it with the below trigger .. But You can use process builder to do this work also 
 
trigger CreateLead on Contact (after insert) {
List<Lead> lstLead = new List<Lead>();
for (Contact con : trigger.new) {
 
	lstLead.add(newLead = new Lead (
		lead.LeadSource = "Sales Development - Inbound",
 		lead.FfirstName = con.FirstName,
		lead.LastName = con.LastName,
		lead.Company = con.Account.Name,
		lead.Email = con.Email,
		lead.Phone = con.Account.Phone,
		lead.Website = con.Account.Website,
		 
		lead.Status = "Open")
	);

}
if(!lstLead.isEmpty()) {
insert lstLead;
}
}

 
Raj VakatiRaj Vakati
Test Class 
@isTest
public class ConTrigger_Test {
static testmethod void testCon(){

Account acc = new Account(Name='Dummy Account',phone='123123123',website='asdasd.com');
		insert acc;
Contact con = new Contact() ;
con.LastName='Test';
con.FirstName='Test';
con.Email='asdasd@sdfsd.com';
con.AccountId =acc.Id ;
insert con ;		
 
}
}