+ 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];
    }
}