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
Apar Jaggi 6Apar Jaggi 6 

I am implementing infinite loading without using promise and the action.setCallback function state is returning error

VinayVinay (Salesforce Developers) 
Hi Apar,

Can you elloborate more on this?

Thanks,
Apar Jaggi 6Apar Jaggi 6
The problem of error is resolved but whenever I scroll my datatable, the loadMoreData function only returns the next 10 records and not executes further i.e even after scrolling only 20 records are visible

loadMoreData:function(component,event,helper){
        event.getSource().set("v.isLoading", true);
        component.set('v.loadMoreStatus', 'Loading....');
        var totalNumberofRows=component.get('v.totalNumberOfRows');
        var currentData=component.get("v.data");
        var counts = component.get("v.currentCount");
        var recordLimit=component.get("v.initialRows");
        if(component.get('v.data').length>=component.get('v.totalNumberOfRows')){
            //console.log("inside if");
                 component.set('v.enableInfiniteLoading', false);
                 component.set('v.loadMoreStatus', 'No more data to load');
        }else{
            var action=component.get("c.fetchRecordData");
            action.setParams({
                recordLimit: recordLimit,
                offSetCount: counts 
            });
            action.setCallback(this,function(response){
                var state=response.getState();
                console.log(state);
                
                if(state === "SUCCESS"){
                    var newData=response.getReturnValue();
                    console.log(newData);
                    var data=currentData.concat(newData);
                    component.set("v.data",data);
                    counts=counts+recordLimit;
                    component.set("v.currentCount",counts);
                    component.set('v.enableInfiniteLoading', true);
                }
            });
            $A.enqueueAction(action);
        }
    }


// apex function
 @AuraEnabled
    public static List<Student__c> fetchRecordData(Integer recordLimit,Integer offSetCount){
        Integer inLimit=Integer.valueOf(recordLimit);
        Integer inOffSet=Integer.valueOf(offSetCount);
        System.debug([SELECT ID, Name,Age__c,Email__c,Course__c FROM Student__c LIMIT:inLimit OFFSET:inOffSet]);
        return [SELECT ID, Name,Age__c,Email__c,Course__c FROM Student__c LIMIT:inLimit OFFSET:inOffSet];
    }