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
Tejas Wadke 5Tejas Wadke 5 

System.ListException: List index out of bounds: 6<init>: line 14, column 1

The code is giving me an error.
 System.ListException: List index out of bounds: 6<init>: line 14, column 1
Please help me on this.

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 ;

VisualForce Page

<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}"/>
Hi Tejas,

List outof bound exception id generally throw when we try to access the index in a list which is not there ,means you are interating the loop 20 times ,however your account and contact list may not contain those many records .
I think you will catch your issue now .

Tejas Wadke 5Tejas Wadke 5
Thanks Manoj