+ Start a Discussion
symantecAPsymantecAP 

Batch Apex Error Message : First error: Argument 1 cannot be null

Hi All I have written a Batch Apex to create records. ( I dont know if I can write bacth Apex to create records.) and scheduled it. I get the following error

 

First error: Argument 1 cannot be null

 

 I am posting the code below.

global class positioncreate implements Database.Batchable<sObject>{
public String query;

global database.querylocator start(Database.BatchableContext BC){
    return Database.getQueryLocator(query);
}
    
global void execute(Database.BatchableContext BC, List<sObject> scope){
Position__c newtd = new Position__c(NAME= 'Salesforce', max_pay__c = 2000, min_pay__c=1000);
 {
insert newtd;
}
       }
  global void finish(Database.BatchableContext BC){}  
}

 

global class positionsched implements Schedulable
{ 
    global void execute(SchedulableContext ctx){
        
      positioncreate accBatch = new positioncreate ();
    
                        
                         
        ID batchprocessid = Database.executeBatch(accBatch);
       
    }
}

 Kindly help as I am learning Batch Apex

 

Thanks

:)

Andy BoettcherAndy Boettcher

You need to define a query in order to use the Batchable interface.  The line that is failing is:  

 

return Database.getQueryLocator(query);

Batchable is designed to have an sObject list of records thrown at it (the query) for doing batch operations on that scope.

symantecAPsymantecAP

Thank you . But can you please let me know what kind of a query might help me to create a record.?