+ Start a Discussion
syeda syedasyeda syeda 

Hi all, i have a few records of contacts about 10. i want to looping the records into 5 chunks but i have faced the below error please give me the correct solution for it.

public class practice {
    list<contact> c;
    list<contact> c1;
    list<contact> c2;
    list<contact> c3;
    list<contact> c4;
    list<contact> c5;
    public practice(){
         c=new list<contact>();
    c1=new list<contact>();
    c2=new list<contact>();
    c3=new list<contact>();
    c4=new list<contact>();
    c5=new list<contact>();
    public void call(){
        c=[select id,lastname from contact];
            if(c.size()!=0)
                for(integer i=0;i<=c.size();i++){
                    for(integer j=0;j<2;j++){
                    c1=c.get(j);
                        c5.add(c1);
                       }
                    for(integer j=2;j<4;j++){
                    c2=c.get(j);
                        c5.add(c2);
                       }
                    for(integer j=4;j<6;j++){
                    c3=c.get(j);
                        c5.add(c3);
                       }
                    for(integer j=6;j<100;j++){
                    c4=c.get(j);
                        c5.add(c4);
                       }
                    
                }
                system.debug(c);
        system.debug(c1);
        system.debug(c2);
        system.debug(c3);
        system.debug(c4);
        system.debug(c5);
            }
        }
}
    
ERROR:expecting a semi-colon, found '('   in line 15
        
        

 
Gopal AgrawalGopal Agrawal
Hi,

Are you really trying to define method inside method?

i.e. call method inside practice method..

Thanks
syeda syedasyeda syeda
Hi,gopal,
        
i have just created one method i.e call and practice is just a constructor is it incorrect to define a method within a constructor. actually i am newbie to salesforce .thats why i would make a mistake.
Thanks
syeda.
Gopal AgrawalGopal Agrawal
Hi,

Please try this code:
public class practice {
    list<contact> c;
    list<contact> c1;
    list<contact> c2;
    list<contact> c3;
    list<contact> c4;
    list<contact> c5;
    public practice(){
         c=new list<contact>();
		c1=new list<contact>();
		c2=new list<contact>();
		c3=new list<contact>();
		c4=new list<contact>();
		c5=new list<contact>();
		}
		public void call(){
			c=[select id,lastname from contact];
            if(c.size()!=0)
                for(integer i=0;i<=c.size();i++){
                    for(integer j=0;j<2;j++){
                    c1=c.get(j);
                        c5.add(c1);
                       }
                    for(integer j=2;j<4;j++){
                    c2=c.get(j);
                        c5.add(c2);
                       }
                    for(integer j=4;j<6;j++){
                    c3=c.get(j);
                        c5.add(c3);
                       }
                    for(integer j=6;j<100;j++){
                    c4=c.get(j);
                        c5.add(c4);
                       }
                    
                }
                system.debug(c);
        system.debug(c1);
        system.debug(c2);
        system.debug(c3);
        system.debug(c4);
        system.debug(c5);
            }
        
}

 
syeda syedasyeda syeda
Hi gopal,
thanks
Gopal AgrawalGopal Agrawal
Hi,

If above solution helped you, Please mark as best answer.

Thanks in advance