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
Amit Jadhav 13Amit Jadhav 13 

Collection size 2,043 exceeds maximum size of 1,000

Collection size 2,043 exceeds maximum size of 1,000  Error Face Any Solution
VisualForce Page :-

<apex:page standardController="Account"  tabstyle="account" sidebar="false" extensions="mergeAccount">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/jq-3.3.1/dt-1.10.18/datatables.min.css" />
<script type="text/javascript" src="https://cdn.datatables.net/v/dt/jq-3.3.1/dt-1.10.18/datatables.min.js"> </script>
     <style> 
          
       
         .dataTables_wrapper .dataTables_paginate .paginate_button.current, .dataTables_wrapper .dataTables_paginate .paginate_button.current:hover {
        color: white!important;
        border: 1px solid #cacaca;
        background-color: white;
        background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, white), color-stop(100%, gainsboro));
        background: -webkit-linear-gradient(top, white 0%, gainsboro 100%);
        background: -moz-linear-gradient(top, white 0%, gainsboro 100%);
        background: -ms-linear-gradient(top, white 0%, gainsboro 100%);
        background: -o-linear-gradient(top, white 0%, gainsboro 100%);
        border-radius: 7px;
        background: dodgerblue;
        }
        <!-- List View (DataTable CSS)-->
        
        .dataTable>tbody>tr:nth-child(even)>td, 
        .dataTable>tbody>tr:nth-child(even)>th {
        background-color: #e8e8e8 !important; 
        }
        
        .dataTable>tbody>tr:nth-child(odd)>td, 
        .dataTable>tbody>tr:nth-child(odd)>th {
        background-color: #d2deea!important; 
        }
        
        .header_styling{
        font-family:Raleway:200;
        background-color: #e1e1e1 !important ; 
        }
        
        .dataTables_length, .dataTables_filter, .dataTables_info, .dataTables_paginate {        
        padding: 3px;        
        }       

        
        
    </style>
 <apex:form id="dForm">
  <apex:pageBlock >
      
      <apex:pageBlockTable value="{!wrapAccountList}" var="a" id="d" styleclass="example" rendered="{!bolvar1}">
        <apex:column >
                        <apex:inputCheckbox value="{!a.selected}" >
                            <!-- <apex:actionSupport action="{!processSelected}"  event="onchange" />-->
                        </apex:inputCheckbox>
                    </apex:column>
        <apex:column value="{!a.acc.name}"/>
        <apex:column value="{!a.acc.type}" />
        <apex:column value="{!a.acc.phone}"/>
            </apex:pageBlockTable>
         <apex:commandButton value="Account Merge" action="{!nextButton}" reRender="dForm" rendered="{!bolvar1}"/>
        <br/>
             <apex:pageblock id="table" rendered="{!bolvar2}">
         choose master account&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    
            <apex:selectList value="{!SelectAccount}" size="1">                                 
                <apex:selectOptions value="{!lstSelectOption}"/>
                 
            </apex:selectList>
                <apex:commandbutton value="Get Selected" action="{!Selectedmaster}"  /> <br/>
                    
                </apex:pageblock>
         
                        
             
        </apex:pageBlock>   
                 
  </apex:form>
  <script>
    $('table.example').DataTable({
       
        "pagingType": "full_numbers"

        });
    </script>
</apex:page>


Controller :-

public class mergeAccount {
    
    public List<wrapAccount> wrapAccountList {get; set;}
    public List<wrapAccount> selectedAccounts{get;set;}
    public Boolean bolvar {get; set;}
    public Boolean bolvar1{get;set;}
    public Boolean bolvar2{get;set;} 
    public Boolean bolvar3{get;set;} 
    public String SelectAccount{get;set;}
    public Account objMasterAccount {get;set;}
    public List<SelectOption> lstSelectOption {get;set;}
    public String AccountId;
    public Account objAccount;
    public string AccountName ;
    public ID AccountID1;
    public List<Account> lstAccount = new List<Account>();
    public List<Account> lstAccount1 = new List<Account>();
    public mergeAccount(ApexPages.StandardController controller) {
        
        system.debug('lstAccount'+lstAccount);
        bolvar1 = true;
        bolvar2 = false;
        //objAccount= (Account)Controller.getRecord().id;
        system.debug('objAccount'+objAccount);
        
        if(wrapAccountList == null) {
            wrapAccountList = new List<wrapAccount>();
            Map<String, Schema.SObjectField> objectFields = Schema.getGlobalDescribe().get('Account').getDescribe().fields.getMap();
            String query='select id';
            for(String s : objectFields.keySet()) {
                if(s != 'Id'){
                    SObjectField test=objectFields.get(s); 
                    //system.debug('test' +test);
                    //if(test.getDescribe().isUpdateable()){ 
                    query += ', ' + s + ' ';
                }
                //}
            }
            
            query +=' FROM Account';
            System.debug(query);
            List<Account> lstAccount = new List<Account>();
            lstAccount = database.query(query);
            //System.debug(lstAccount);
            for(Account a: lstAccount) {
                wrapAccountList.add(new wrapAccount(a,bolvar));
                
                
            }
        }
    }
    
    public void getAccountNames() {
       lstSelectOption= new List<SelectOption>();
        lstSelectOption.add( new SelectOption('','--Select--'));
        for( wrapAccount wrapacc :  selectedAccounts) {
            lstSelectOption.add( new SelectOption(wrapacc.acc.Id,wrapacc.acc.name));
           system.debug('accOptions'+lstSelectOption);
        }   
    }
    
    public void nextButton(){
        selectedAccounts = new List<wrapAccount>();
        for(wrapAccount wrapAccountObj : wrapAccountList) {
            if(wrapAccountObj.selected == true) {
                selectedAccounts.add(new wrapAccount(wrapAccountObj.acc,wrapAccountObj.selected));  
            }
        }
        getAccountNames();
        bolvar1 = false;
        bolvar2 = true;
        
    }
    
    public PageReference  Selectedmaster(){
        objMasterAccount = new Account();
        objAccount = new Account();
        SobjectField[] fields =  Schema.getGlobalDescribe().get('Account').getDescribe().fields.getMap().values();
        System.debug(fields);
        for(wrapAccount wrapacc :selectedAccounts){
            if(wrapacc.acc.id == SelectAccount) 
                objMasterAccount = wrapacc.acc;
            //AccountID1 = wrapacc.accId;
            system.debug('objMasterAccount'+objMasterAccount);
        }
        
        for( wrapAccount wrapacc :selectedAccounts){
            if(wrapacc.acc.id != SelectAccount){
                for(SObjectField field:fields){  
                    if(field.getDescribe().isUpdateable()){   
                        system.debug('masterLead.get(field)'+objMasterAccount.get(field));
                        if(objMasterAccount.get(field)==null && wrapacc.acc.get(field)!=null ){     
                            objMasterAccount.put(field,wrapacc.acc.get(field));
                        }
                    }
                }
            }
        }
        update objMasterAccount;
        bolvar3 = false; 
        PageReference pageRef = new PageReference('/apex/PopUp');
        pageRef.setRedirect(true);
        return pageRef;
    }
    
    public PageReference ok(){
        PageReference pageRef = new PageReference('/001/o');
        pageRef.setRedirect(true);
        return pageRef; 
    }
    
    public class wrapAccount {
        public Account acc {get; set;}
        public Boolean selected {get; set;}
        //public id accId {get;set;}
        public wrapAccount(Account a,Boolean bolvar) {
            acc = a;
            selected = bolvar;
            //accId = aId;
        }
    } 
}
Valentin F.Valentin F.
Hi Amit,
You can find a workaround here : http://kuldeeptyagi.blogspot.com/
Have a good day,
Valentin
Khan AnasKhan Anas (Salesforce Developers) 
Hi Amit,

Greetings to you!

It means List, Set & Map size exceeded more than 1000 to be shown on the Visualforce page. To avoid this, use wrapper class and get set of first 1000 records, save it and then retrieve the next and so on. 

Also, please refer to the below links which might help you further with the above issue.

https://salesforce.stackexchange.com/questions/116092/why-can-visualforce-iterate-over-1000-item-collection-if-its-a-map

https://salesforce.stackexchange.com/questions/221782/collection-size-1-768-exceeds-maximum-size-of-1-000

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas