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
Nikita Dhamal 4Nikita Dhamal 4 

Error: Compile Error: Illegal assignment from List<Lead> to lead at line 14 column 5

vf code:
<apex:page standardController="Lead" action="{!convertLead}" extensions="ControllerLeadConvertView"> </apex:page>
controller:
public class ControllerLeadConvertView {
  public Id leadId;
    public String convertedAccountId ;
    public ControllerLeadConvertView(ApexPages.StandardController stdController){
        leadId = ApexPages.CurrentPage().getParameters().get('id');
        
    }

     
    public PageReference convertLead(){
    try
    {
    lead leadobj=new Lead();
    leadobj = [select id,MobilePhone,Company from lead where id =:leadId];
    Account a = new Account();
    a.Name =leadobj.Company;  
    insert a;
    PageReference newocp= new PageReference('/'+ a.Id);

     newocp.setRedirect(true);

           return newocp;

     }   
               
    catch(Exception e)
    {
            System.Debug('Error - ControllerLeadConvertView.convertLead - Exception [' + e.getMessage() + ']');
            return null;
    }     
}
}

 
Best Answer chosen by Nikita Dhamal 4
Sumit Kumar Singh 9Sumit Kumar Singh 9
Is there any class in your Org with name 'lead' ??

All Answers

Amit Chaudhary 8Amit Chaudhary 8
Please try below code.
public class ControllerLeadConvertView {
  public Id leadId;
    public String convertedAccountId ;
    public ControllerLeadConvertView(ApexPages.StandardController stdController){
        leadId = ApexPages.CurrentPage().getParameters().get('id');
    }
    public PageReference convertLead()
	{
		try
		{
			Lead leadobj = new Lead();
			
			List<Lead> lstLead = [select id,MobilePhone,Company from lead where id =:leadId limit 1];
			if( lstLead.size() > 0 )
			{
				leadobj = lstLead[0];
			}
			Account a = new Account();
			a.Name =leadobj.Company;  
			insert a;
			PageReference newocp= new PageReference('/'+ a.Id);
			newocp.setRedirect(true);
			return newocp;
		}   
		catch(Exception e)
		{
				System.Debug('Error - ControllerLeadConvertView.convertLead - Exception [' + e.getMessage() + ']');
				return null;
		}     
	}
}

Please let us know if this will help you
 
Sumit Kumar Singh 9Sumit Kumar Singh 9
Is there any class in your Org with name 'lead' ??
This was selected as the best answer
rachit rakesh7rachit rakesh7
Hi 

At the moment when I am trying to replicate the issue then this code is working fine but this error occurs when we get more than one record and we are trying to store that in a instance of an related object rather than list of that object.
Thanks
Sumit Kumar Singh 9Sumit Kumar Singh 9
Simply, you can put Limit 1 in the SOQL QUERY. YOur problem will get resolved
Nikita Dhamal 4Nikita Dhamal 4
@Sumit Kumar Singh 9 your question was right.. i had a class named lead which was causing the problem.. thnks!!