top of page

Using List of Lists

Updated: May 30, 2020

List<List<Integer>> l = new List<List<Integer>>();


List<Integer> k = new List<Integer>();

for(Integer ctr=0; ctr<3; ctr++ ){

for(Integer j=0; j<3; j++){

k.add(j);

}

l.add(k);

}


for(Integer ctr=0; ctr<3; ctr++ ){

System.debug('List ' + ctr + ' of following lists: ');

for(Integer j=0; j<3; j++){

System.debug( l[ctr][j]);

}

}

Output:


Eg:

List<List<sObject>> searchList = [FIND 'Wingo OR SFDC' IN ALL FIELDS

RETURNING Account(Name),Contact(FirstName,LastName,Department)];

//returns account lists stored in the list[0]

Account[] searchAccounts = (Account[])searchList[0];

//returns account lists stored in the list[1]

Contact[] searchContacts = (Contact[])searchList[1];

System.debug('Found the following accounts.');

for (Account a : searchAccounts) {

System.debug(a.Name);

}

System.debug('Found the following contacts.');

for (Contact c : searchContacts) {

System.debug(c.LastName + ', ' + c.FirstName);

}

Recent Posts

See All

Comments


Post: Blog2_Post

©2020 by SalesforceDemystified. Proudly created with Wix.com

bottom of page