function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ken_KoellnerKen_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.

 

 

Best Answer chosen by Admin (Salesforce Developers) 
Venkat PolisettVenkat Polisett

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

Venkat PolisettVenkat Polisett

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.

 

 

Ken_KoellnerKen_Koellner

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?  

 

Venkat PolisettVenkat Polisett

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. 

 

 

This was selected as the best answer
Ken_KoellnerKen_Koellner

The second paragraph answers the question.

 

_tmayo__tmayo_
Venkat - how would I reference such a class?