2

I have this Apex batch having issues with call. I am new in this apex-world. Can someone help me out. My code is here.

global class Samplelotinactive implements Database.Batchable<Sample_Lot_vod__c>
{
    Public String query;
    Public String email;

    global Database.QueryLocator start(Database.BatchableContext BC)
    {
        query = 'SELECT ID,Active_vod__c FROM Sample_Lot_vod__c where Expiration_Date_vod__c=NEXT_N_DAYS:60 and Active_vod__c=true'; //need to define query
        return Database.getQueryLocator(query);
    }
    global void execute(Database.BatchableContext BC, List<Sample_Lot_vod__c> m)
    {
        List<Sample_Lot_vod__c> m1 = [SELECT ID,Active_vod__c FROM Sample_Lot_vod__c where Expiration_Date_vod__c=NEXT_N_DAYS:60 and Active_vod__c=true];
        for (Sample_Lot_vod__c s: m){
            s.Active_vod__c=false;
        }
        update m;
    }

    global void finish(Database.BatchableContext BC)
    {
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        mail.setToAddresses(new String[]{email});
        mail.setReplyTo('saikatkumarneogy@gmail.com');
        mail.setSenderDisplayName('Batch Processing Completed');
        mail.setPlainTextBody('Sample lots inactivated');
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
    }
}
3
  • So what is your current issue? What do you mean by having issues with call. – Lance Shi Jul 23 '14 at 6:29
  • Hi Lance, sorry if I am not clear about it. I get this type error. Error: Compile Error: Samplelotinactive: Class must implement the global interface method: Iterable<SOBJECT:Sample_Lot_vod__c> start(Database.BatchableContext) from Database.Batchable<SOBJECT:Sample_Lot_vod__c>, Samplelotinactive: Class must implement the global interface method: void finish(Database.BatchableContext) from Database.Batchable<SOBJECT:Sample_Lot_vod__c> at line 1 column 14 – Testing_SFDC Jul 23 '14 at 6:43
  • I have to inactivate the flag value for all those records that are returned by the SOQL query. Please let me know the way out. – Testing_SFDC Jul 23 '14 at 6:46
4

Database.Batchable nominally supports parameterised types (using the <> notation) but it appears that when returning Database.QueryLocator rather Iterable from the start method you have to stick to <SObject>.

(Note that returning Database.QueryLocator rather than Iterable from the start method usually gives better performance and allows the batchable to process up to 50 million records rather than hitting a governor limit at 50,000 records.)

This will compile and execute:

global class Abcd implements Database.Batchable<SObject>
{
    global Database.QueryLocator start(Database.BatchableContext BC)
    {   ...
        return Database.getQueryLocator(query);
    }
    global void execute(Database.BatchableContext BC, List<Sample_Lot_vod__c> m)
    {
        ...
    }
    global void finish(Database.BatchableContext BC)
    {
        ....
    }
}
1
  • @saikat Cool. Click the tick to accept the answer so people know that the question no longer needs answering. – Keith C Jul 23 '14 at 14:00
0

I guess what you need is just a finish class - even if it is empty:

global void finish(Database.BatchableContext BC){
}

To use batch apex, you can follow this guide: http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_batch_interface.htm

It should direct you to the right place

1
  • Thanks Lance. I tried it. Updated my code here. Still seeing this error. Error: Compile Error: Samplelotinactive: Class must implement the global interface method: Iterable<SOBJECT:Sample_Lot_vod__c> start(Database.BatchableContext) from Database.Batchable<SOBJECT:Sample_Lot_vod__c> at line 1 column 14 – Testing_SFDC Jul 23 '14 at 7:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.