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
PseudodarwinistPseudodarwinist 

Need Help:Visual force page not working as expected

There is general error that we are facing with a visual force page and Controller.We are trying to query for all the duplicates in the system but since the volume is huge and Salesforce imposes a 50k query record limit, we run it multiple times . We have implemented an Alert on the page (alert('{!oldQueryFlag}');).It pops up first time when the page loads and second time when the query returns more than 50k records but it should run again and give us the alert because the record is more than 50k but it does not happen.Can somebody help us with identifying the issue. It needs an immidiate help.I am pretty sure its a delicate miss.

Page:
<<apex:page controller="ExtDupGoldenIDDataController" id="thePage" ><!--contentType="application/vnd.ms-excel#FILENAME.xls" cache="true">-->
    <apex:form id="thefrm">
        <apex:actionFunction id="af1" name="GoldenRecordIDsAF" action="{!GoldenRecordIDs}" reRender="op"/>
        <apex:actionFunction id="af2" name="AccountGoldenLstAF" action="{!AccountGoldenLst}" reRender="thefrm,op"/>
        <apex:pageBlock >
            <apex:pageBlockTable value="{!accountLst}" var="a" rendered="{!oldQueryFlag && newQueryFlag && accountLst!=null && accountLst.size>0}">
                <apex:column value="{!a.ID}"/>
                <apex:column value="{!a.R1_ACC_TXT_Id_Golden_record__c}"/>
                <apex:column value="{!a.CreatedDate}"/>
            </apex:pageBlockTable>
        </apex:pageBlock>
        <apex:outputPanel id="op">
            <script type="text/javascript">
                alert('{!oldQueryFlag}');
                </script>
            <apex:outputPanel id="op1" rendered="{!oldQueryFlag==false}">
                <script type="text/javascript">
                    window.onload = function () {
                        GoldenRecordIDsAF();
                    }
                </script>
            </apex:outputPanel>
            <apex:outputPanel id="op2" rendered="{!oldQueryFlag==true && newQueryFlag==false}">
                <script type="text/javascript">
                    window.onload = function () {
                        AccountGoldenLstAF();
                    }
                </script>
            </apex:outputPanel>
        </apex:outputPanel>
    </apex:form>
</apex:page>


Controller:
public class ExtDupGoldenIDDataController{
    public String sDate{get;set;}
    
    public Set<String> goldenIDSet{get;set;}
    public Set<String> queriedGLDIDSet{get;set;}
    
    public Boolean oldQueryFlag{get;set;}
    public Boolean newQueryFlag{get;set;}
    public DateTime sTime{get;set;}
    public DateTime eTime{get;set;}
    
    public List<Account> accountLst{get;set;}
    
    public ExtDupGoldenIDDataController(){
        sDate = ApexPages.currentPage().getParameters().get('sd');
        String ids = ApexPages.currentPage().getParameters().get('gID');
        goldenIDSet = new Set<String>();
        queriedGLDIDSet = new Set<String>();
        accountLst = new List<Account>();
        oldQueryFlag = false;
        newQueryFlag = false;
        if(sDate!=null && sDate!=''){
            //prepare startTime and endTime
            sTime = datetime.valueOf(sDate+' 00:00:00');
            eTime = datetime.valueOf(sDate+' 23:59:59');
        }
    }
    
    public void GoldenRecordIDs(){
        system.debug('<<getGoldenRecordIDs>>');
        if(!oldQueryFlag){
            String query = 'SELECT ID,R1_ACC_TXT_Id_Golden_record__c, CreatedDate FROM Account'
                +' WHERE CreatedDate>=:sTime and CreatedDate<=:eTime and R1_ACC_TXT_Id_Golden_record__c!=null'
                +' AND R1_ACC_TXT_Id_Golden_record__c NOT IN :goldenIDSet LIMIT 50000';
            List<Account> accLst = Database.query(query);
            for(Account a : accLst){
                goldenIDSet.add(a.R1_ACC_TXT_Id_Golden_record__c);
            }
            system.debug('<<getGoldenRecordIDs>>'+goldenIDSet.size());
            if(accLst.size()<50000){
                oldQueryFlag=true;
            }
        }
    }
    
    public void AccountGoldenLst(){
        system.debug('<<getAccountLst>>');
        if(oldQueryFlag && !newQueryFlag && goldenIDSet.size()>0){
            String query = 'SELECT ID,R1_ACC_TXT_Id_Golden_record__c, CreatedDate FROM Account'
            +' WHERE R1_ACC_TXT_Id_Golden_record__c IN :goldenIDSet'
            +' AND R1_ACC_TXT_Id_Golden_record__c!=null AND CreatedDate<=:sTime AND CreatedDate>=:eTime';
            List<Account> accLst = Database.query(query);
            for(Account a : accLst){
                accountLst.add(a);
            }
            newQueryFlag=true;
        }
    }
    
}