+ Start a Discussion
bhagya manshanibhagya manshani 

how to Convert lead to Account Plz help

Pla help

Arvind1Arvind1

Map the fields in Lead to Account by clicking on Map lead fields.

 

Then convert the lead to account using Convert button in detail page

 

Thanks

Arvind

bhagya manshanibhagya manshani

First of all Thanks You so much for Reply. i need to do using apex code ...............95% its has been done  using apex code.

doing final testing..............

bhagya manshanibhagya manshani

hi Dear ...........

 I have Done it...................... Proper Code to Convert Lead To Account & Contact

// Here is the Apex class  

 

public class tester {
public static void ConvertLead(lead[] leads)
{
  Database.LeadConvert[] leadsToConvert = new Database.LeadConvert[0];
  Database.LeadConvert converter = new Database.LeadConvert();
for (lead l : leads){
  
  converter.setLeadId(l.id);
  String company = l.Company;
  account account = new account(name = company);
  insert account;
  converter.setAccountId(account.id);
  //contact contact = new contact(firstname='test', lastname='test', accountid=account.id);
 // insert contact;
 // converter.setContactId(contact.id);
  //converter.setOwnerId('00570000000oflK');
   LeadStatus convertStatus = [Select Id, MasterLabel from LeadStatus where IsConverted=true limit 1];
    //lc.setConvertedStatus(convertStatus.MasterLabel);
  converter.setConvertedStatus(convertStatus.MasterLabel);
  converter.setDoNotCreateOpportunity(true);
  
  
  leadsToConvert.add(converter);
 }
  Database.ConvertLead(leadsToConvert,true);
}
}

 

 

// here is the trigger to call that class 

 

  trigger tester on Lead (after insert) {

 

  System.debug('hi');

  tester.convertLead(trigger.new);

 

}