[SalesForce] common.apex.runtime.impl.ExecutionException: SObject row was retrieved via SOQL without querying the requested field: Contact.bp_Billing_Address_1__c

I am trying to display a value from list which is created from multi-joined SOQL and though the field is part of SOQL statement, I still get the error:

common.apex.runtime.impl.ExecutionException: SObject row was retrieved via SOQL without querying the requested field: Contact.bp_Billing_Address_1__c

Here in my controller:

public  class BP_GeneratePDFCC {

   public list <CaseContactRole> getTodaysCases(){
      List <CaseContactRole> myCases =  [SELECT                          
                                cases.createddate,
                                cases.casenumber, 
                                cases.StreetType__c, 
                                cases.AptNum__c, 
                                cases.ZipCode__c, 
                                cases.DirPrefix__c,
                                cases.DirSuffix__c,
                                cases.StreetName__c, 
                                cases.State__c, 
                                cases.LotNum__c, 
                                cases.HouseNum__c,
                                cases.BP_IsTXNM__c,
                                cases.fldSBlockNum__c,
                                cases.order__r.BP_fldPendType__c,
                                contact.name ,                                   
                                contact.bp_CAddress_1__c , 
                                contact.bp_CCity__c,
                                contact.bp_CState__c, 
                                contact.bp_CZipCode__c
                                FROM 
                                    CaseContactRole 
                                WHERE 
                                    Role = 'Primary Contact'];
       return myCases;        
   }     



}

And here is my page. Note that I am rendering the page as pdf.

<apex:page controller="BP_GeneratePDFCC" renderAs="pdf" showHeader="false" sidebar="false" standardStylesheets="false" applyBodyTag="false" applyHtmlTag="false">
    <head>
        <style>
            body {
                font-family: Georgia, serif;
                background: none;
                color: black;
                size: 10px;
            }
            @page {
                size: letter;
                margin: 0.25in;
            }
        </style>
    </head>

    <body>
        <apex:repeat value="{!TodaysCases}" var="c">
            <div >
                <apex:outputText >{!c.CaseContactRole.Contact.Name}</apex:outputText>
                <br />
                <apex:outputText >{!c.CaseContactRole.Contact.bp_Billing_Address_1__c}</apex:outputText>
                <br />
                <apex:outputText >{!c.Contact.bp_CBillingCity__c}, {!c.Contact.bp_CBillingState__c}-{!c.Contact.bp_CBillingZipCode__c}</apex:outputText>
                 <br />
            </div>
            <div style="page-break-after:always;" />
         </apex:repeat> 
    </body> 
</apex:page>

Best Answer

You have to query "Contact.bp_Billing_Address_1__c" this field too. like:

List <CaseContactRole> myCases =  [SELECT                          
                                cases.createddate,
                                cases.casenumber, 
                                cases.StreetType__c, 
                                cases.AptNum__c, 
                                cases.ZipCode__c, 
                                cases.DirPrefix__c,
                                cases.DirSuffix__c,
                                cases.StreetName__c, 
                                cases.State__c, 
                                cases.LotNum__c, 
                                cases.HouseNum__c,
                                cases.BP_IsTXNM__c,
                                cases.fldSBlockNum__c,
                                cases.order__r.BP_fldPendType__c,
                                contact.name ,                                   
                                contact.bp_CAddress_1__c , 
                                contact.bp_CCity__c,
                                contact.bp_CState__c, 
                                contact.bp_CZipCode__c,
                                Contact.bp_Billing_Address_1__c
                                FROM 
                                    CaseContactRole 
                                WHERE 
                                    Role = 'Primary Contact'];