function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
chowdary marellachowdary marella 

trigger for lead convert

How to map a custom field in lead to custom fields in both account and opportunity?..how can i write a trigger?

Vinit_KumarVinit_Kumar

You need to create an update Trigger on Lead and need to use ConvertAccountId and ConvertedOpportunityId which would be generated in Lead conversion.Please go through the below link to know more about these fields :-

 

http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_lead.htm

ItswasItswas
trigger MappedAccountIdOpportunityId on Lead (before insert)
{ Database.LeadConvert[] leadsToConvert = new Database.LeadConvert[];
Database.LeadConvert converter = new Database.LeadConvert();
for(Lead objll : Trigger.New)
{ converter.setLeadId(objll.id);
Account account = new Account(name='Test_Covertlead',NumberOfEmployees = objll.NumberOfEmployees);
insert account;
converter.setAccountId(account.id);
Contact contact = new Contact(firstname='test', lastname='test',accountid=account.id);
insert contact;
converter.setContactId(contact.id);
converter.setConvertedStatus('Qualified - Converted');
converter.setDoNotCreateOpportunity(false);
leadsToConvert.add(converter);}
Database.ConvertLead(leadsToConvert,true);
}
Hi marella,
Please prefer the above code and let me know whether it works for you or not.

Reagrds,
Itswas.