2

I am running Batch Class for Migration of Records for Particular Object and I am storing Failed Records in an another Object. Now I have run the Batch and I got 1,00,000+ Records which are Failed. But Using the SOQL I can only get 50000 records. Following is the query for getting Failed Records.

SELECT Id, IsDeleted, Name, CreatedDate, CreatedById, LastModifiedDate, LastModifiedById, SystemModstamp, Record_ID__c, Record_Name__c, Error__c,Batch_Result__r.Batch_Id__c FROM Batch_Status__c where Batch_Result__r.Batch_Id__c =:strBatchId

Thanks in Advance!!

3
  • can you explain why you need so much data and what are you gonna achieve with it? you can use ReadOnly annotation to query more OR use batch api to process that chunk by chunk, or salesforce BULK API for third party integration.
    – kurunve
    Commented Jul 21, 2016 at 9:14
  • This is used for Migration of Data Commented Jul 21, 2016 at 9:58
  • What data migration tool are you using?
    – Nick C
    Commented Jul 21, 2016 at 13:34

3 Answers 3

1

You can get more than 50,000 using a Query Locator.

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_database_batch.htm

This documentation says you can query up to 50 million records: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_batch_interface.htm

however, query locators have some risks where are well documented here: https://help.salesforce.com/apex/HTViewSolution?id=000004410&language=en_US

1

You can use something like this? (this is basically a summary of How to do batch in apex)

//THIS IS HOW YOU EXECUTE
//Id batchInstanceId = Database.executeBatch(new transactionRecords()); 
global class transactionRecords implements Database.Batchable<sObject>{

    String query;

    global transactionRecords(){
        this.query = 'SELECT Id FROM Transaction__c';
    }

    global Database.QueryLocator start(Database.BatchableContext BC){
        return Database.getQueryLocator(query);
    }

    global void execute(Database.BatchableContext BC, List<sObject> scope){
        ....YOUR CODE...
    }

    global void finish(Database.BatchableContext BC){
    }
}

Then you can see it in apex jobs enter image description here

0

Use Salesforce workbench to query such records. Workbench uses the salesforce rest/tooling API that doesn't have 50K record limitation.

https://workbench.developerforce.com/query.php

It might happen that it will fail for 4-5 times due to huge amount of data but it would work .

Other option include exporting data as csv using reports .

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .