Lead Conversion in Salesforce: Lead is Converted into Account and Contact,if we Want Opportuinty we can set , while Creating the Lead Record,Name Should be Converted to Contact,Company Should be Converted into Account
I Want Trigger Code:If name and Company what you are Giving in the Lead Record is Already Exists,lead should be Converted but Converted name and Company is Pointed out to the Existing Contact and Account Record,No New Contact and Account Should be Created
I Have Tried in So Many Ways, I am Not able to find out the Answer.
This is My tried Trigger Code:
trigger myfirstlead100 on Lead (after insert)
{
for(lead cf:trigger.new)
{
lead cd= new lead(id=cf.id);
Database.LeadConvert lc = new database.LeadConvert();
lc.setLeadId(cd.id);
lc.setDoNotCreateOpportunity(true);
Database.LeadConvertResult lcr = Database.convertLead(lc);
System.assert(lcr.isSuccess());
Profile pf = [Select id,name from Profile where name ='test' limit 1];
Contact con = [select id,name,email,lastname,firstname,accountid from contact where id=:lcr.getcontactid()limit 1];
}
}
Please Anyone Guide Me for the Answer