I'm having a problem displaying lead information from a custom controller extension. The class looks like this:
public class LeadDuplicateManagement{
public List<Lead> similarLeads { get; private set; }
public Lead currentlead { get; set;}
private ApexPages.StandardController ctrl;
//initialize class with standard controller parameter
public LeadDuplicateManagement(ApexPages.StandardController stdController){
ctrl = stdController;
currentlead = (Lead)ctrl.getRecord();
String id = currentLead.Id;
String ownerFirstName = currentlead.Owner_First_Name__c;
String ownerLastName = currentlead.Owner_Last_Name__c;
similarLeads = [SELECT ID, Owner_First_Name__c, Owner_Last_Name__c, Phone1__c, Phone2__c, Phone3__c
FROM Lead
WHERE Owner_First_Name__c = :ownerFirstName
AND Owner_Last_Name__c = :ownerLastName
AND id != :id];
}
}
If I do the below for visualforce markup, everything works fine:
<apex:page StandardController = "Lead" extensions = "LeadDuplicateManagement" >
{!currentlead.Owner_First_Name__c} {!currentlead.Owner_Last_Name__c} {!currentlead.Phone1__c} {!currentlead.id} {!lead.Owner_First_Name__c} {!lead.Owner_Last_Name__c} {!lead.Phone1__c} {!lead.Phone2__c} {!lead.Phone3__c}
etc...
However everything breaks and throws an error if I just do this instead:
<apex:page StandardController = "Lead" extensions = "LeadDuplicateManagement" >
{!currentlead.Owner_First_Name__c} {!currentlead.Owner_Last_Name__c}
etc...
The error thrown is
System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: Lead.Owner_First_Name__c
Why do I get this error? How can I fix it?