+ Start a Discussion
Prady01Prady01 

How to work with a nested List

Hello All, I was just wondering if I could get a sample code of using nested list i.e. example
List<List<Set<Integer>>> my_list_2 = new List<List<Set<Integer>>>();
Just wondering what will be usage of the nested lists (Any pros and cons) and how to add entities to nested list and get it back.

Thanks
Prady
Best Answer chosen by Prady01
bob_buzzardbob_buzzard
I very rarely use a nested list, as it doesn't really give you any information about what is stored in the nested list, aside from the position in the parent list.  One use case would be for the rows for a table, where each entry in the list is the set of columns to output for the row.

I often use Maps containing lists - typically the key will be the id of a parent record and the list will be related records. An example of this would be storing the contacts related to an account, with the map keyed by the account id.

All Answers

bob_buzzardbob_buzzard
I very rarely use a nested list, as it doesn't really give you any information about what is stored in the nested list, aside from the position in the parent list.  One use case would be for the rows for a table, where each entry in the list is the set of columns to output for the row.

I often use Maps containing lists - typically the key will be the id of a parent record and the list will be related records. An example of this would be storing the contacts related to an account, with the map keyed by the account id.
This was selected as the best answer
Jigar TrivediJigar Trivedi
Hi Prady, I hope this link will give you the answer you wanted.

https://developer.salesforce.com/forums/ForumsMain?id=906F000000091MlIAI