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
JenLJenL 

VF Page as Related List Error

I am creating a VF page rendered as a PDF and would like to display Account information and active programs from the Program_c object (Program_c has master detail relationship with Account)

 

I am getting this error:

 

SObject row was retrieved via SOQL without querying the requested field: Program__c.Active__c

 


Below is the code for my Class:

 

public class ActiveProgramsExtension {
    
    Account CurrentAccount = null;
    List<Program__c> ActivePrograms = null;
    
    public ActiveProgramsExtension(ApexPages.StandardController controller) {
        CurrentAccount = (Account)controller.getRecord();
        ActivePrograms = [SELECT Id, Name FROM Program__c WHERE Account__c= :CurrentAccount.Id and Active__c=TRUE];
    }
    
    public List<Program__c> getActivePrograms() { return ActivePrograms; }
    
     public static testMethod void testContactsExtension()
    {
        Account testAccount = new Account(Name='Dev Church of the Sandbox',ISO_Code__c='US');
        
        ApexPages.StandardController controller  = new ApexPages.StandardController(testAccount);
      ActiveProgramsExtension BEC = new ActiveProgramsExtension(controller);
      List<Program__c> ActivePrograms = BEC.getActivePrograms();
    }
}

 

And here is the code for my page:

 

<apex:page standardController="Account" extensions="ActiveProgramsExtension" showHeader="false" renderAs="pdf">
    <apex:pageBlock title="Account Profile">

          <apex:pageBlockTable value="{!ActivePrograms}" var="ActiveProg">
             <apex:column >
                <apex:outputLink value="/{!ActiveProg.Id}" target="_parent">{!ActiveProg.Name}</apex:outputLink>
            </apex:column>
            <apex:column value="{!ActiveProg.Active__c}" />
            
            </apex:pageBlockTable>
    </apex:pageBlock>
     
</apex:page>

 

 

HELP!!!!

 

Best Answer chosen by Admin (Salesforce Developers) 
ManjunathManjunath

Hi,

 

In constructorActiveProgramsExtension you are not querying the fields Active__c. That is the reason your getting the error.

Use this, it will solve that.

ActivePrograms = [SELECT Id, Name,Active__c FROM Program__c WHERE Account__c= :CurrentAccount.Id and Active__c=TRUE];

 

Regards,