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
Akhil R NathAkhil R Nath 

Hi, I have write a code for find duplicates in Lead(more than3 million records). I need to display all duplicates in visualforce page. Please help When I am using OFFSET I can only display 2000 records

public class leadDuplicate {
    
    public List<lead>ac{get;set;}
    public List<lead>ldList{get;set;}
    public List<lead>ldEmail{get;set;}
    public List<lead>ldLastName{get;set;}
    public List<lead>ldFirstName{get;set;}
    public List<AggregateResult> ac1 {get; set;}
    public List<AggregateResult> ac2 {get; set;}
    public List<AggregateResult> ac3 {get; set;}
    public List<AggregateResult> ac4 {get; set;}
    public Boolean bFirstName {get; set;}
    public Boolean bLastName {get; set;}
    public Boolean bEmail {get; set;}
    public Boolean bLead {get; set;}
    public Boolean bCompany{get;set;}
    public List <String> companyList= new List<String>();
    public List <String> EmailList= new List<String>();
    public List <String> firstNameList= new List<String>();
    public List <String> lastNameList= new List<String>();
    public string Email;
    public string Company;
    public string FirstName;
    public string LastName;
    private integer totalRecs = 0;       
    private integer index = 0;  
    private integer blockSize = 2000;
    public List<Lead> ldlistNew= new List<Lead>();
    
    
    public leadDuplicate(ApexPages.StandardController controller){
        
        //totalRecs = [select count() from Lead]; 
        //Duplicate();
        Email = apexpages.currentpage().getparameters().get('Email');
        Company = apexpages.currentpage().getparameters().get('Company');
        FirstName = apexpages.currentpage().getparameters().get('FirstName');
        LastName = apexpages.currentpage().getparameters().get('LastName');
        system.debug('Email'+Email);
        system.debug('Company'+Company);
        system.debug('FirstName'+FirstName);
        system.debug('LastName'+LastName);
        
        if(FirstName=='True' || LastName=='True' || Email=='True' || Company=='True'){
            Duplicate();
        }
        
        
    }
    public void beginning() {  
        
        index = 0;  
        
    }  
    
    public void previous() {  
        Duplicate();
        index = index - blockSize;  
        
    }  
    
    public void next() {  
        
        index = index + blockSize;  
        system.debug('indexnext'+index);
        Duplicate();
    }  
    
    public void end() {  
        Duplicate();
        index = totalrecs - math.mod(totalRecs,blockSize);  
        
    }          
    
    public boolean getprev() { 
        Duplicate();
        if(index == 0)  
            return true;  
        else  
            return false;  
        
    }    
    
    public boolean getnxt() {  
        Duplicate();
        if((index + blockSize) > totalRecs)  
            return true;  
        else  
            return false;  
        
    }          
    public PageReference Duplicate(){
        firstNameList.clear();
        lastNameList.clear();
        EmailList.clear();
        companyList.clear();
        
        ldList = new List<Lead>();
        if(FirstName=='True' || LastName=='True' || Email=='True' || Company=='True'){
            if(FirstName=='True'){
                //ac1=[SELECT FirstName,count(Id) count1 FROM lead GROUP BY FirstName HAVING count(Id)>1];
                for(AggregateResult ag : [SELECT FirstName,count(Id) count1 FROM lead GROUP BY FirstName HAVING count(Id)>1]) {
                    Lead ldFirstName = new Lead();
                    
                    ldFirstName.FirstName = (String) ag.get('FirstName');
                    firstNameList.add(ldFirstName.FirstName);
                    
                    
                }
                system.debug('firstNameList'+firstNameList);
            }
            system.debug('firstNameList'+firstNameList);
            system.debug('bLastName'+bLastName);
            if(LastName=='True'){  
                system.debug('bLastName'+bLastName);
                //ac2=[SELECT LastName,count(Id) count1 FROM lead GROUP BY LastName HAVING count(Id)>1];
                for(AggregateResult ag : [SELECT LastName,count(Id) count1 FROM lead GROUP BY LastName HAVING count(Id)>1]) {
                    Lead ldLastName = new Lead();
                    ldLastName.LastName = (String) ag.get('LastName');
                    lastNameList.add(ldLastName.LastName);
                    
                }
                system.debug('lastNameList'+lastNameList);
            }
            
            if(Email=='True'){
                //ac3=[SELECT email,count(Id) count1 FROM lead GROUP BY email HAVING count(Id)>1];
                for(AggregateResult ag : [SELECT email,count(Id) count1 FROM lead GROUP BY email HAVING count(Id)>1]) {
                    Lead ldEmail = new Lead();
                    ldEmail.Email = (String) ag.get('Email');
                    EmailList.add(ldEmail.Email);
                    
                }
            }
            if(Company=='True'){
                //ac4=[SELECT Company,count(Id) count1 FROM lead GROUP BY Company HAVING count(Id)>1];
                for(AggregateResult ag : [SELECT Company,count(Id) count1 FROM lead GROUP BY Company HAVING count(Id)>1]) {
                    Lead ld = new Lead();
                    ld.Company = (String) ag.get('Company');
                    companyList.add(ld.Company);
                    
                }
            }
            
            //integer totalrecs   = [select count() from Lead];
            ldlistNew=[SELECT Id, Email, FirstName, LastName,Company,LeadSource    From Lead Where Company IN:companyList OR Email IN:EmailList OR FirstName IN:firstNameList OR LastName IN:lastNameList LIMIT :blockSize OFFSET :index ];
            system.debug('ldList'+ldList);
            for(Lead ld:ldlistNew){
                if(ld.Email!=Null){
                    ldList.add(ld);
                }
            }
        }
        PageReference pr=new PageReference ('https://na139.salesforce.com/apex/LeadDuplicateDisplayPage?Email='+bEmail+'&Company='+bCompany+'&FirstName='+bFirstName+'&LastName='+bLastName);
        return pr;
        
    }
}
AbhishekAbhishek (Salesforce Developers) 
https://salesforce.stackexchange.com/questions/42702/how-to-paginate-10000-records-soql-offset-and-standardsetcontroller-too-limit

This developer discussion has a workaround for your issue, Check it once.


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.

Thanks.