In Apex programming there is no such limit defined on storing the records in a list, instead there a limit on heap size which is 6MB (Synchronous), so if you will store large amount of data in collection(List Set Map), it will give heap size error, so use getHeapSize() to handle it dynamically.
In context of showing List data on VF page, A list can hold 1000 elements, however if you use readOnly annotation on page than it can store records upto 2000.
Neither the question is clear or the "correct answer" is helpful. Depends on what you want as a key and what you want as a value. Let's assume you want the lead Email as a key and the the Lead object as the value. This is what you should do:
List<Lead> myLeads = [SELECT Id, Email, Name, LastName FROM Lead];
Map<String, Lead> myLeadMap = new Map<String, Lead>();
for (Lead lead : myLeads) {
if (lead.Email != NULL || lead.Email == '') {
myLeadMap.put(lead.Email, lead);
}
}
System.debug(myLeadMap);
Mr Faiz provided the answer that brought me here, regarding list capacity in APEX code (not for showing records on VF page), there is no limit of records. The limit is on heap size and I would add, on CPU time as well, like in this example:
List <lead> leadList = new List <Lead>();
for (Integer i = 0 ; i < 1000000 ; i++){
Lead myLead = new Lead();
myLead.lastName = 'myLead' + i;
leadList.add(myLead);
}
System.Debug(leadList.size());
A list can hold 1000 elements(as per the limit).
set<String> email= [select email from Lead];
List<Lead> leads= [select name from Lead];
and you can assign them in a map like this:
map<email, leads> newmap=new map<email, leads>();
All Answers
A list can hold 1000 elements(as per the limit).
set<String> email= [select email from Lead];
List<Lead> leads= [select name from Lead];
and you can assign them in a map like this:
map<email, leads> newmap=new map<email, leads>();
In Apex programming there is no such limit defined on storing the records in a list, instead there a limit on heap size which is 6MB (Synchronous), so if you will store large amount of data in collection(List Set Map), it will give heap size error, so use getHeapSize() to handle it dynamically.
In context of showing List data on VF page,
A list can hold 1000 elements, however if you use readOnly annotation on page than it can store records upto 2000.
Heap size limits:
Synchronous : 6MB
Asynchronous : 12 MB
Email services: 36 MB
Best Regards
Faiz Ahmed
Depends on what you want as a key and what you want as a value.
Let's assume you want the lead Email as a key and the the Lead object as the value.
This is what you should do: