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
Violeta GrigorovaVioleta Grigorova 

I have an extension controller and a SOQL query, which produces the error: SObject row was retrieved via SOQL without querying the requested field: Account.AccountNumber

I have a custom Object SBQQ__Subscription__c. It has some fields that I want to retrieve. This is my controller:

public with sharing class ActiveController_2 {
    
    private ApexPages.StandardController stdController;
    private final Account acct;

    public ActiveController_2(ApexPages.StandardController stdController) {
        this.stdController = stdController;
        this.acct = (Account)stdController.getRecord();
     }

public List<SBQQ__Subscription__c> getSubscriptions() {
        List<SBQQ__Subscription__c> subscriptionResults = [SELECT Name, MasterDeviceName__c, SBQQ__ProductName__c, Location__c, DeviceId__c, SBQQ__ContractNumber__c, Server_Status__c  FROM SBQQ__Subscription__c WHERE DeviceId__c LIKE :acct.AccountNumber];
        return subscriptionResults;
    }
}

I get the following errror: SObject row was retrieved via SOQL without querying the requested field: Account.AccountNumber 

I read through the forum and I saw that there are other people having the same issue and I get that I should mention Account.AccountNumber somewhere in my query, but I cannot understand how.

Also, I went through the WSDL of our organisation and here is what I found on the SBQQ__Subscription__c object:

<complexType name="SBQQ__Subscription__c">
<complexContent>
<extension base="ens:sObject">
<sequence>
<element name="SBQQ__Account__c" nillable="true" minOccurs="0" type="tns:ID"/>
<element name="SBQQ__Account__r" nillable="true" minOccurs="0" type="ens:Account"/>


If you could give me an idea of what is going on in here?
Thank you,
Violeta
{!pramod_nishane}{!pramod_nishane}
Hi Violeta,

Try below line in your visualforce Page:-

<apex:outputField value="{!Account.AccountNumber}" rendered="false"/>

Since you are using standard controller you have to  use the field on the page to have it available in the controller method.

Let me know in case of any concerns.

Please mark this answer as the solution/ best answer if it solves your purpose so that it can help other community members.

Thanks,
Pramod Nishane
Salesforce Consultant
Varasi LLC
www.varasi.com
Vyankatesh ChoulwarVyankatesh Choulwar
Hi Violeta,

You can solve this error be either of below 2 ways:

1. Make below change in your controllers constructor:

  public ActiveController_2(ApexPages.StandardController stdController) {
        this.stdController = stdController;
        Id accID = (Account)stdController.getRecord().id;
        this.acct =  [Select Id , Name, AccountNumber from Account where Id =: accID];
}

OR
2. Write below line of code in your VF Page :
<apex:outputField value="{!Account.AccountNumber}" rendered="false"/>

Let me know if you get any issues.
Please mark this answer as best answer if it solves your issue.

Thanks,
Vyankatesh Choulwar