1

I am trying to write a batch apex class to pass a number of field values to new fields, all on the account object. However I am having trouble compiling my class.

Error: Class MigrateCreditSafe must implement the method: System.Iterable<Account> Database.Batchable<Account>.start(Database.BatchableContext)

global class MigrateCreditSafe implements Database.Batchable<Account> {

    global MigrateCreditSafe(){}

    global Database.QueryLocator start(Database.BatchableContext bc) {
        return Database.getQueryLocator(
            'SELECT Id, bottomline_creditSafeScore__c, bottomline__creditSafeCompanyType__c, bottomline__creditSafeScoreDescription__c, bottomline__creditSafeLastRefreshed__c, ' +
                                                                                     'bottomline__creditSafeLimit__c, bluetahiti_creditSafeScore__c, bluetahiti__creditSafeCompanyType__c, ' +
                                                                                     'bluetahiti__creditSafeScoreDescription__c, bluetahiti__creditSafeLastRefreshed__c, ' +
                                                                                     'bluetahiti__creditSafeLimit__c  FROM Account WHERE bottomline__creditSafeCompanyType__c != null'
        );
    }

    global void execute(Database.BatchableContext bc, List<Account> scope) {
       List<Account> accounts = new List<Account>();
       for(Account account : scope){
            bottomline_creditSafeScore__c = bluetahiti_creditSafeScore__c;
            bottomline__creditSafeCompanyType__c = bluetahiti__creditSafeCompanyType__c;
            bottomline__creditSafeScoreDescription__c = bluetahiti__creditSafeScoreDescription__c;
            bottomline__creditSafeLastRefreshed__c = bluetahiti__creditSafeLastRefreshed__c;
            bottomline__creditSafeLimit__c = bluetahiti__creditSafeLimit__c;
            // add accounts to list to be updated
            accounts.add;
       }
       update accounts; 
    }
    global void finish(Database.BatchableContext bc) {}
}
3
  • Try to replace Database.Batchable<Account> with Database.Batchable<SObject> Commented Jan 9, 2018 at 14:03
  • @AbhishekDaware's change will address the problem - not sure why the compiler works that way. You will also need to change the accounts.add; line.
    – Keith C
    Commented Jan 9, 2018 at 14:05
  • Thank you! Hmm, I have made the above change, now it is saying that variables do not exist for all fields in the SOQL query - do I need to reference them differently now?
    – CharniW
    Commented Jan 9, 2018 at 14:21

2 Answers 2

1

You have a number of problems with your code. I'll comment them below:

// To use a QueryLocator, it must be the SObject Type
global class MigrateCreditSafe implements Database.Batchable<SObject> {
    /* default constructor not necessary unless you have a non-default constructor */
    // global MigrateCreditSafe(){}

    global Database.QueryLocator start(Database.BatchableContext bc) {
        // When possible, use an inline query instead of a string.
        // This prevents typos by allowing the compiler to validate fields.
        // Also, you don't need to query the bottomline fields, because you're not accessing their values.
        // Namespace and field name are always separated by __, not _
        return Database.getQueryLocator(
            [SELECT bluetahiti__creditSafeScore__c, bluetahiti__creditSafeCompanyType__c, bluetahiti__creditSafeScoreDescription__c, 
                    bluetahiti__creditSafeLastRefreshed__c, bluetahiti__creditSafeLimit__c  
            FROM Account WHERE bottomline__creditSafeCompanyType__c != null]
        );
    }

    global void execute(Database.BatchableContext bc, List<Account> scope) {
       // no need to "copy the list", just use scope directly
       // List<Account> accounts = new List<Account>();
       for(Account account : scope){
            // You need to reference a "variable", in this case, account.
            // Looks like a missing _ on the following line, too.
            account.bottomline__creditSafeScore__c = account.bluetahiti__creditSafeScore__c;
            account.bottomline__creditSafeCompanyType__c = account.bluetahiti__creditSafeCompanyType__c;
            account.bottomline__creditSafeScoreDescription__c = account.bluetahiti__creditSafeScoreDescription__c;
            account.bottomline__creditSafeLastRefreshed__c = account.bluetahiti__creditSafeLastRefreshed__c;
            account.bottomline__creditSafeLimit__c = account.bluetahiti__creditSafeLimit__c;
            // if you needed this line, you'd have to specify the record to add:
            // accounts.add(account);
       }
       // Update the records in the database
       update scope; 
    }
    global void finish(Database.BatchableContext bc) {}
}
1
  • thank you so much - particularly for adding all of the comments, really helps to learn rather than just get the class working! Much appreciated!
    – CharniW
    Commented Jan 9, 2018 at 16:21
1

The problem is in the start method. You don't have to return the querylocator.

Change the Database.getQueryLocator for Database.query

You must log in to answer this question.

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