0

While i'm displaying set data into vf page it's showing the error

vf code :--

<apex:page controller="Soql_Ct">
    <apex:form >
        <apex:pageBlock title="Soql_Example" >

            <apex:pageBlockTable value="{!accounts}" var="a">
                    <apex:column value="{!a.Id}"/>

            </apex:pageBlockTable>
         </apex:pageBlock>
    </apex:form>
</apex:page>

apex code:--

public class Soql_Ct {
    public Set<Account> accounts {set;get;}
    public List<Account> myList {set;get;}
    public Soql_Ct(){
        myList=[select Id,Name,Phone,Industry,Rating,Ownership from Account];
        accounts=new Set<Account>();
        accounts.addAll(myList);
    }    
}
  • Have you tried iterating it through myList instead of accounts.? – Rohit Mourya Jan 17 at 12:59
0

By default when iterating through Set<SObject> on visualforce page using any iterator, it returns as a String and not of Object type. In your case, a is a string type and not sobject. When you try to access the a.id it gives you an error.

Declare accounts as a List<Account> else use myList in your Visualforce page.

|improve this answer|||||
0

I have just made a simple change. Try out with this.Set will only include unique values.Suppose your account with 2 different id but same names. This will only take one value. Or just use the same myList to return

public class Soql_Ct {
public list<Account> accounts {set;get;}
public List<Account> myList {set;get;}
public Soql_Ct (){
    myList=[select Id,Name,Phone,Industry,Rating,Ownership from Account];
    accounts=new list<Account>();
    accounts.addAll(myList);
}    

}

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.