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
sessusessu 

hi

Hi I need to dConvert lead to Account and contact. with the help of ashish I am able to convert in account but Not able to display lead details in contact related list of account. as account is a look up field in contact kindly let me know the code for look up field. My code has error error is Error Error: Compile Error: Illegal assignment from Schema.SObjectField to SOBJECT:Account at line 15 column 5 public class CMyLeadControllerExtension { public ApexPages.StandardController LEAD; public CMyLeadControllerExtension(ApexPages.StandardController stdController) { this.LEAD = stdController; } Lead abc = [select Id,Name, Email, Company,MobilePhone from Lead where id = :apexpages.currentpage().getparameters().get('id')]; public pageReference doCreateAccount(){ Account newacc = new Account(); newacc.Name = abc.Company; insert newacc; Contact newcon = new Contact(); newcon.LastName = abc.Name; newcon.Account= Account.id; ----------------------------------------- newcon.MobilePhone = abc.MobilePhone; newcon.Email = abc.Email; newcon.FirstName = abc.Name; insert newcon; pageReference p = new pageReference('/' + newacc.id); p.setRedirect(true); return p; } }
Navatar_DbSupNavatar_DbSup

Hi,

You are getting this error because you are assigning wrong value for accounted on contact. Try the below code as reference:

public class CMyLeadControllerExtension

 {

 public ApexPages.StandardController LEAD;

 public CMyLeadControllerExtension(ApexPages.StandardController stdController)

 {

 this.LEAD = stdController;

 }

 Lead abc = [select Id,Name, Email, Company,MobilePhone from Lead where id = :apexpages.currentpage().getparameters().get('id')];

 public pageReference doCreateAccount()

 {

 Account newacc = new Account();

 newacc.Name = abc.Company;

 insert newacc;

 Contact newcon = new Contact();

 newcon.LastName = abc.Name;

 newcon.Accountid= newacc.id;

 newcon.MobilePhone = abc.MobilePhone;

 newcon.Email = abc.Email;

 newcon.FirstName = abc.Name;

 insert newcon;

 pageReference p = new pageReference('/' + newacc.id);

 p.setRedirect(true);

 return p;

 }

 }

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

sessusessu
Hi Thanks this code worked
sessusessu
I have created a button for converting a lead into an account and contact, extending the functionality of the same button i need to create an Opportunity. when a lead is converted. I need to insert the value of Stage field as 'Prospecting', and close date to be 1 month from the lead conversion date. The data for these two fields must not be inserted from lead object by creating fields in leads. Please help me to write a code for this: public class CMyLeadControllerExtension { public ApexPages.StandardController LEAD; public CMyLeadControllerExtension(ApexPages.StandardController stdController) { this.LEAD = stdController; } Lead abc = [select Id,Name, Email, Company,MobilePhone,Account__c, Stage__c, Close_Date__c from Lead where id = :apexpages.currentpage().getparameters().get('id')]; public pageReference doCreateAccount(){ Account newacc = new Account(); newacc.Name = abc.Company; insert newacc; Contact newcon = new Contact(); newcon.LastName = abc.Name; newcon.AccountId= newacc.id; newcon.MobilePhone = abc.MobilePhone; newcon.Email = abc.Email; newcon.FirstName = abc.Name; insert newcon; Opportunity opp = new Opportunity(); opp.Name = abc.Company; insert opp; pageReference p = new pageReference('/' + newacc.id); p.setRedirect(true); return p; } }