I want to create a quick action button that call to apex class that execute a batch(I used a batch because I want to retrieve More than 50000 records and I have salesforce limitation). I want to take the list that I get from the batch and export it to csv file. I created apex method that has a list and the batch update that list I want to retrieve this list to client side (lighting) and export this data to csv file can someone have an idea how to do this request with the best way? this is my code: Apex class:
public with sharing class PRT_EntitlementTableCtrl {
@AuraEnabled
public static List<Entitlement> element{get;set;}
@AuraEnabled
public static List<Entitlement> getRecordsForTable(Map<String, String> filters){
element = new List<Entitlement>();
String whereClause = getWhereClause(filters);
PRT_Batch_Entitlement shn = new PRT_Batch_Entitlement(whereClause);
database.executeBatch(shn);
return element;
}
Batch job:
public class PRT_Batch_Entitlement implements Database.Batchable<sObject>{
public String query{get;set;}
public String whereClause;
public PRT_Batch_Entitlement(String strParam){
whereClause = strParam;
}
public Database.QueryLocator start(Database.BatchableContext BC){
System.debug('start batch');
System.debug('param : '+ whereClause);
query = 'SELECT ID, Legacy_End_User_Company__c, Asset_Reference_WF__c, Asset_CPU_ID__c, Service_Name__c, Status, EndDate, ServiceContractSalesOrder__c, AssetSalesOrder__c ' +
'FROM Entitlement '+
whereClause + 'Limit 200';
System.debug('query : '+ query);
return Database.getQueryLocator(query);
}
public void execute(Database.BatchableContext BC, List<sObject> scope){
System.debug('execute batch');
System.debug('scope : '+scope);
for(sObject obj : scope){
PRT_EntitlementTableCtrl.element.add((Entitlement)obj);
}
}
public void finish(Database.BatchableContext BC){
System.debug('finish batch');
}
}