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
Josh Brown 14Josh Brown 14 

Export all Account data to S3 nightly

Hello,

I'm been trying to figure out how to get a list of all 167,000 accounts and put them in a csv and upload to S3 nightly. I'm running into multiple issues, mainly the size of the row return and uploading to S3 on a schedule. For the first part, i've been trying to use a Batchable class to bypass the 50,000 row limit, but Batchables don't allow @future calls, so I can't upload to S3. So then I tried using Queueable to bypass the @future problem, but I run into the 50,000 row limit. Is there a way to do this or am I stuck?
Ravi Dutt SharmaRavi Dutt Sharma
Hi Josh,

From the batch class, instead of calling a future method, you can call a Queueable class. Will this fulfill your use case?
 
global class Batch1 implements Database.Batchable<sObject> {
    
    global Database.QueryLocator start(Database.BatchableContext BC) {
        String query = 'SELECT Id FROM Account';
        return Database.getQueryLocator(query);
    }
    
    global void execute(Database.BatchableContext BC, List<Account> scope) {
        System.enqueueJob(new Queueable1());
    }   
    
    global void finish(Database.BatchableContext BC) {
       // logic here
    }
}
 
public class Queueable1 implements Queueable{

    public void execute(QueueableContext context){
        // whatever logic you have in future method, you can place it here
    }
}

 
Josh Brown 14Josh Brown 14
Hi Ravi,

Thank you for this! I was trying to go that route, but I need to push the final csv to the queueable class so that the csv can be uploaded to S3, but I couldn't figure out how to add a parameter to the queueable class. Could you help me with that?

Batch Class
global class BatchScheduleExport implements Database.Batchable<sObject> {
    global String csv = 'parent_case_safe_id,case_safe_id,account_name,shipping_state_province,shipping_zip_postal_code\n';   	
    global Database.QueryLocator start(Database.BatchableContext BC) {
        String query = 'Select Ultimate_Parent_ID__c, Case_Safe_ID__c, Name, ShippingState, ShippingPostalCode FROM Account';
        return Database.getQueryLocator(query);
    }
    
    global void execute(Database.BatchableContext BC, List<Account> scope)
    {	
        for (Account acct : scope) {
            csv += acct.Ultimate_Parent_ID__c + ',' + acct.Case_Safe_ID__c + ',' + acct.Name.escapecsv() + ',' + acct.ShippingState + ',' + acct.ShippingPostalCode + '\n'; 
        }         
        System.enqueueJob(new test_queueable());		
    }
    
    global void finish(Database.BatchableContext BC) {
        
    }
    
    
}

Queueable Class
public class test_queueable implements Queueable, Database.AllowsCallouts {
    public void execute(QueueableContext context) {   
        	saveToS3(csv);  
        }
        }
 	public static void saveToS3(String file_object){
               //Code to upload file_object to S3
}