i have a requirement, where i am holding list(1000) of email address into one set, and with that i need to split them in to 100 in each sublist and make queryString need to perform sosl query.

 set<integer> nms= new set<integer>();
string str;
integer setindex=0;
for(integer i=0;i<100;i++)


set<integer> temp= new set<integer>();
for(integer i=0;i<nms.size()/10;i++)

    for(integer j=0;j<30;j++ )
        str=str +string.valueOf(j)+' or ';


   if(setindex== nms.size())


can any one help me fix this issue.


  • similar to: Apex Array Slice
    – martin
    Jun 23, 2017 at 3:03
  • Why do you need to slice your array? If you're expecting less than 2000 rows, you can do it all at once.
    – sfdcfox
    Jun 23, 2017 at 3:13

1 Answer 1


This is a good application of the slice function that I posted a question about earlier this week.

I recommend using the version provided by Adrian or the version provided by sfdcfox.

To extend this (rather than just linking the question) you also need to divide your list into sets of 100.

You would implement this like so:

String[] yourEmailList;
for (Integer i = 0; i< 9; i++){
  Integer a = i*100;
  Integer b = (i+1)*100;
  String[] emailSublist = Utility.slice(yourEmailList,a,b);
  //perform sosl

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .