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
Michael MMichael M 

Help with Controller extension

Hello,
My Controller extension is supposed to query some records, but it is not working- the visualforce page is not displaying any records when the query should be returning. Is there an issue with this controller?

Here is the page:
<apex:page standardController="Discharge__c" extensions="CbosOldListExtension" lightningStylesheets="true">
    <apex:pageBlock title="Referrals/CBO History">
  <apex:pageBlockTable value="{!listofCbos}" var="cbolist">
   <apex:column >
    <apex:facet name="header">Referral Date</apex:facet>
    <apex:outputText value="{!cbolist.referral_date__c}"/>
   </apex:column>
   <apex:column >
    <apex:facet name="header">CBO Type</apex:facet>
    <apex:outputText value="{!cbolist.cbo_type__c}"/>
   </apex:column>
   <apex:column >
    <apex:facet name="header">CBO Name</apex:facet>
    <apex:outputText value="{!cbolist.cbo_name__c}"/>
   </apex:column>
   <apex:column >
    <apex:facet name="header">Referral Status</apex:facet>
    <apex:outputText value="{!cbolist.referral_status__c}"/>
   </apex:column>
   <apex:column >
       <apex:facet name="header">Rejection/Cancellation Reason</apex:facet>
    <apex:outputText value="{!cbolist.rejection_cancellation_reason__c}"/>
   </apex:column>
        <apex:column >
    <apex:facet name="header">Start of Service</apex:facet>
    <apex:outputText value="{!cbolist.start_of_service__c}"/>
   </apex:column>
   <apex:column >
       <apex:facet name="header">End of Service</apex:facet>
    <apex:outputText value="{!cbolist.end_of_service__c}"/>
   </apex:column>
  </apex:pageBlockTable>
</apex:pageBlock>
</apex:page>

And the Controller:
public with sharing class CbosOldListExtension {
    
private final Discharge__c dis;
    
    Public List<Cbo__c> listofCbos {get; set;}
    
    Public CbosOldListExtension(ApexPages.StandardController stdController){
        this.dis = (Discharge__c)stdController.getRecord();
        try{
        Id myDischargeId = [Select Id, Name, Date_of_Birth__c from Discharge__c where Id = :this.dis.id].Id;
        String myDischargeName = [Select Name from Discharge__c where Name = :this.dis.name].name;
        //Date myDischargeDOB = [Select Id, Name, Date_of_Birth__c from Discharge__c where Name = :this.dis.id].Date_of_Birth__c;
        string myDischargeSSN = [Select Id, Name, ssn__c from Discharge__c where ssn__c = :this.dis.id].ssn__c;
        
        listofCbos = [SELECT Discharge_name__c, cbo_type__c, cbo_name__c, referral_date__c, referral_status__c, 
                      rejection_cancellation_reason__c, start_of_service__c, end_of_service__c 
                      FROM CBO__c 
                      WHERE discharge_name__r.name = :myDischargeName];
                 //  and   discharge_name__r.ssn__c = :myDischargeSSN];
        }
        catch(exception e){
            Apexpages.addMessage(new ApexPages.Message(ApexPages.SEVERITY.FATAL, 'No old records'));
        }
    }
}
 
Dev-FoxDev-Fox
Hi Michael,
Try quering the field this.dis.name separately after this.dis = (Discharge__c)stdController.getRecord(); statement.
Getrecord() will not fetch inner entities.
Please mark as best if it works.
Thanks.
Michael MMichael M
Can you show me what that would look like?