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
Navneeth RajNavneeth Raj 

System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: Account.Type ERROR

Apex Class
public class SOQLExample {
    public String type {get;set;}
    public List<Account> accs {set;get;}
    public void getResult(){
        accs=[SELECT id,name FROM Account WHERE Type=:type];
    }
}
Vfp
<apex:page controller="SOQLExample">
    <apex:form >
        <apex:pageBlock title="soql example">
            <apex:outputText value="Enter Type:"/>  
                <apex:inputText value="{!Type}"/>
                <apex:commandButton value="Submit" action="{!getResult}"/>
        </apex:pageBlock>
        <apex:pageBlock title="Result" rendered="{! !ISNULL(accs)}">
            <apex:pageBlockTable value="{!accs}" var="account">
                <apex:column value="{!account.name}"/>
                <apex:column value="{!account.type}"/>
            </apex:pageBlockTable>
        </apex:pageBlock>
            </apex:form>
</apex:page>
What could be the error
KaranrajKaranraj
You have used Type field in your visualforce page, but you haven't queried that field in your SOQL query, you have used only in where condition. Include Type field in the select statement of the SOQL query, it should work
public class SOQLExample {
    public String type {get;set;}
    public List<Account> accs {set;get;}
    public void getResult(){
        accs=[SELECT id,name,Type FROM Account WHERE Type=:type];
    }
}