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
mr.sollismr.sollis 

VF page on Lead Layout throwing error

Hey all,

 

I had this working, made a few changes, and can not for the life of me find now why it will not work.  I am creating a VF page that will rend on the lead layout.  Simple Page that will show all lead records that have the same email address on the page layout and a few fields from the lead.

 

At one point this all worked, and I've buggered something up.  Thanks for the help!

 

Error I'm getting "Content cannot be displayed: SObject row was retrieved via SOQL without querying the requested field: Lead.Email"

 

Here is the controller:

 

public class LeadLookupCon {
    
    public Lead lookupLead;
    
    List<Lead> leads;
    public String sortField {get; set;}
    public String previousSortField {get; set;}   
    
    public LeadLookupCon(ApexPages.StandardController controller) {
        this.lookupLead = (Lead)controller.getRecord();
    }

    public List<Lead> getLeads() {
        if(leads == null) leads = [select id,createddate,name,company, email,LeadSource, Event_Name__c,productinterest__c,inquiry_stage__c from lead where email=:lookupLead.email ORDER BY createddate desc];
        return leads;
    }
    
    public void doSort(){
        String order = 'asc';
        /*This checks to see if the same header was click two times in a row, if so it switches the order.*/
        if(previousSortField == sortField){
            order = 'desc';
            previousSortField = null;
        }else{
            previousSortField = sortField;
        }
        adbeSort.sortList(leads,sortField,order);

    }
}

 

 

Here is the VF Page:

<apex:page standardController="Lead" extensions="LeadLookupCon" standardStylesheets="true" showHeader="false" sidebar="false" tabStyle="Lead">
    <style>
        .even { background: #fff;}
    </style>
    <apex:form >
    <apex:pageBlock title="Previous Engagement History" tabStyle="Lead" >
        <apex:pageBlockTable value="{!leads}" var="lead" id="theTable" rowClasses="odd,even" styleClass="tableClass" cellpadding="5" width="100%">
            <apex:column >
                <apex:facet name="header">
                    <apex:commandLink value="{!$ObjectType.Lead.Fields.Company.Label}" action="{!doSort}" rerender="theTable">
                            <apex:param name="sortField" value="Company" assignTo="{!sortField}"/>
                    </apex:commandLink>
                </apex:facet>
                <apex:outputText value="{!lead.company}"/>
            </apex:column>
            <apex:column >
                <apex:facet name="header">
                    <apex:commandLink value="{!$ObjectType.Lead.Fields.Name.Label}" action="{!doSort}" rerender="theTable">
                            <apex:param name="sortField" value="Name" assignTo="{!sortField}"/>
                    </apex:commandLink>
                </apex:facet>
                <apex:outputLink value="/{!lead.id}">{!lead.name}</apex:outputLink>
            </apex:column>
            <apex:column >
                <apex:facet name="header">{!$ObjectType.Lead.Fields.Email.Label}</apex:facet>
                <apex:outputLink value="/{!lead.id}">{!lead.Email}</apex:outputLink>
            </apex:column>
            <apex:column >
                <apex:facet name="header">
                    <apex:commandLink value="{!$ObjectType.Lead.Fields.ProductInterest__c.Label}" action="{!doSort}" rerender="theTable">
                        <apex:param name="sortField" value="ProductInterest__c" assignTo="{!sortField}"/>
                    </apex:commandLink>
                </apex:facet>
                <apex:outputText value="{!lead.ProductInterest__c}"/>
            </apex:column>
            <apex:column >
                <apex:facet name="header">
                    <apex:commandLink value="{!$ObjectType.Lead.Fields.LeadSource.Label}" action="{!doSort}" rerender="theTable">
                        <apex:param name="sortField" value="LeadSource" assignTo="{!sortField}"/>
                    </apex:commandLink>
                </apex:facet>
                <apex:outputText value="{!lead.leadsource}"/>
            </apex:column>
            <apex:column >
                <apex:facet name="header">
                    <apex:commandLink value="{!$ObjectType.Lead.Fields.Event_Name__c.Label}" action="{!doSort}" rerender="theTable">
                        <apex:param name="sortField" value="Event_Name__c" assignTo="{!sortField}"/>
                    </apex:commandLink>
                </apex:facet>
                <apex:outputText value="{!lead.Event_Name__c}"/>
            </apex:column>
            <apex:column width="75px" >
                <apex:facet name="header">
                    <apex:commandLink value="{!$ObjectType.Lead.Fields.Inquiry_Stage__c.Label}" action="{!doSort}" rerender="theTable">
                        <apex:param name="sortField" value="Inquiry_Stage__c" assignTo="{!sortField}"/>
                    </apex:commandLink>
                </apex:facet>
                <apex:outputText value="{!lead.Inquiry_Stage__c}"/>
            </apex:column>
            <apex:column width="100px" >
                <apex:facet name="header">
                    <apex:commandLink value="{!$ObjectType.Lead.Fields.createddate.Label}" action="{!doSort}" rerender="theTable">
                        <apex:param name="sortField" value="createddate" assignTo="{!sortField}"/>
                    </apex:commandLink>
                </apex:facet>
                <apex:outputText value="{!lead.createddate}"/>
            </apex:column>
        </apex:pageBlockTable>
    </apex:pageBlock>
    </apex:form>
</apex:page>

 

:

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
sravusravu

Make the following changes to your code and see if it works:

 

public class LeadLookupCon {
    
    private final Lead lookupLead;
    
    List<Lead> leads;
    public Lead l;
    public String sortField {get; set;}
    public String previousSortField {get; set;}  
    
   // private final String LeadEmail = ApexPages.currentPage().getParameters().get('email');
    
    public LeadLookupCon(ApexPages.StandardController controller) {
     this.lookupLead = (Lead) controller.getRecord();
     l = [select id,email from Lead where id=:ApexPages.currentPage().getParameters().get('id')];
    }
        public List<Lead> getLeads() {
        if(leads == null) leads = [select id,email,createddate,name,company,LeadSource, Event_Name__c,productinterest__c,inquiry_stage__c from lead where  email=:l.email ORDER BY createddate desc];
        system.debug(leads);
        return leads;
    }
         
   public void doSort(){
        String order = 'asc';
                if(previousSortField == sortField){
            order = 'desc';
            previousSortField = null;
        }else{
            previousSortField = sortField;
        }
       adbeSort.sortList(leads,sortField,order);

    }  
}

 

Let me know if you need further assistance.

All Answers

sravusravu

Make the following changes to your code and see if it works:

 

public class LeadLookupCon {
    
    private final Lead lookupLead;
    
    List<Lead> leads;
    public Lead l;
    public String sortField {get; set;}
    public String previousSortField {get; set;}  
    
   // private final String LeadEmail = ApexPages.currentPage().getParameters().get('email');
    
    public LeadLookupCon(ApexPages.StandardController controller) {
     this.lookupLead = (Lead) controller.getRecord();
     l = [select id,email from Lead where id=:ApexPages.currentPage().getParameters().get('id')];
    }
        public List<Lead> getLeads() {
        if(leads == null) leads = [select id,email,createddate,name,company,LeadSource, Event_Name__c,productinterest__c,inquiry_stage__c from lead where  email=:l.email ORDER BY createddate desc];
        system.debug(leads);
        return leads;
    }
         
   public void doSort(){
        String order = 'asc';
                if(previousSortField == sortField){
            order = 'desc';
            previousSortField = null;
        }else{
            previousSortField = sortField;
        }
       adbeSort.sortList(leads,sortField,order);

    }  
}

 

Let me know if you need further assistance.

This was selected as the best answer
mr.sollismr.sollis

That worked.  Thank you.  Any idea why the controller.getRecord() did not work?

sravusravu

" getRecord() returns the record that is currently in context, based on the value of the id query string parameter in the
Visualforce page URL. Only the fields that are referenced in the associated Visualforce markup are available for querying
getRecord SObject on this SObject. All other fields, including fields from any related objects, must be queried using a SOQL expression"

 

Hope this will help you understand the problem