+ Start a Discussion

When to use list and sets in a bulk trigger

I Have a big confussion in using lists and set  in triggers can any one guide me when to use list and sets in trigger

Yoganand GadekarYoganand Gadekar

Difference between list and set is that set holds only unique values while list can have duplicates.


If you are stroing id then use sets

Lists genrally hold records,

for example a query will return you list of records,

List<account> accList = [select id ,name from account limit 12];


It depends how you use it in trigger,


may be you can store your record id's in set(while you iterate over trigger.nw) and then use the set to query, implemt your logic.



There is very nice post over this here http://wiki.developerforce.com/page/Best_Practice:_Bulkify_Your_Code

Have a look, You will able to figure out the differences, why to use and when to use