You need to sign in to do that
Don't have an account?
Ken_Koellner
Is there a Limits method for Set/List/Map
The document says the limit on a Set/List/Map is 1000 in all contexts.
I checked the Limits class here -- http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_limits.htm
There's no mention of a method for Set/List/Map. Is this because it's hard-coded in all contexts to 1000?
I don't really want to hard-code 1000 but I guess I will have to if there is no method to get the limit.
Maintain that limit by yourself in a Static class. When APEX limits are changed in future, make change to that class.
Currently, there is no machanism that you can use to search for APEX limit for number elements in a Collection, other than hard checking the limit or using a Static class.
All Answers
You can have more than one collection (SET/LIST/MAP) in your code. Each collection is limited to 1000 elements. There is not limit to the number collection variables that you can have in your script.
Limits class is meant to track limits for items like soql queries, max records, call outs, future annotations etc., that are imposed per script or for an entire org.
An element in a Collection can be another Collection too. So technically, you can have more than 1000 elements in a collection.
For instace,
List<List<Account>> accountsList = new List<List<Account>>();
From the above, you can technically have 1000 * 1000 account records.
Hope this helps.
That's interesting but it doesn't answer the question.
Suppose I want a List of List and I want to write code to load it. I'd want an inner loop with a limit of 1000. I would think it better coding practice to get that 1000 value from a Limits method call than to hard-code 1000 in my code. Suppose in a future release SFDC changes it to 5000, or maybe changes the limit in test context to 500?
Maintain that limit by yourself in a Static class. When APEX limits are changed in future, make change to that class.
Currently, there is no machanism that you can use to search for APEX limit for number elements in a Collection, other than hard checking the limit or using a Static class.
The second paragraph answers the question.