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
admin 7admin 7 

Multiple Objects in Pageblock table using Wrapper class: Error: tt Compile Error: Illegal assignment from List<Account> to List<RNK.account> at line 9 column 9

<apex:page controller="tt">
    <apex:pageBlock >
        <apex:pageBlockSection >
            <apex:pageBlockTable value="{!wrapper}" var="wrap">
                <apex:column headerValue="Account Name" value="{!wrap.accRec.Name}"/>
                <!-- you can add related fields here   -->
                <apex:column headerValue="Contact Name" value="{!wrap.conRec.Name}"/>
            </apex:pageBlockTable>
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:page>



Controller:

public class tt
{
    public List<Account> accLst {get; set;}
    public List<Contact> conLst {get; set;}
    public List<MyWrapper> wrapper {get; set;}

    public tt()
    {
        accLst = [select id,name from account   ] ;
        conLst = [select id,name from contact   ] ;
        wrapper = new List<MyWrapper>() ;
        for(Integer i=0 ;i<20;i++)
            wrapper.add(new MyWrapper(accLst[i] , conLst[i])) ;
    }
    
    public class MyWrapper
    {
        public Account accRec {get; set;}
        public Contact conRec {get; set;}
        
        public MyWrapper(Account acc , Contact con)
        {
            accRec = acc ;
            conRec = con ;
        }
    }
}
Best Answer chosen by admin 7
Shailendra Singh ParmarShailendra Singh Parmar
Good idea Naveen to try in other org. It works great in my developer account and i can see table. here is screen of outputUser-added image

I think, their is Apex class, trigger or something custom in your org with Account name

All Answers

Shailendra Singh ParmarShailendra Singh Parmar
Hi Naveen,
All seems good in your example, Could you check if you have class with name of "account" in your org and that is confusing salesforce.com b/w Standard Account and your custom Account class.

Thanks!
admin 7admin 7
Thanks for reply Shailendra. I checked all the things but i am getting this error could you check in your org please.

Error: tt Compile Error: Illegal assignment from List<Account> to List<RNK.account> at line 9 column 9
Shailendra Singh ParmarShailendra Singh Parmar
Good idea Naveen to try in other org. It works great in my developer account and i can see table. here is screen of outputUser-added image

I think, their is Apex class, trigger or something custom in your org with Account name
This was selected as the best answer