You need to sign in to do that
Don't have an account?
Navneeth 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
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
Karanraj
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