+ Start a Discussion
yamini prakasam 10yamini prakasam 10 

In batch class can we directly insert record in execute method without writing anything in start method

Chetan PaulChetan Paul
No, because start() method must return either Database.QueryLocator or Iterable<sObject>.
If we do not write anything in start(), it will give error as "Missing return statement required return type: System.Iterable<SObject>"
Indian government scheme (https://www.letsuppro.com) central government yojana ...
Bryan Leaman 6Bryan Leaman 6
No, but you can simply return a single, empty SObject like this:
global Iterable<SObject> start(Database.BatchableContext bc) {
    List<Account> objlist = new List<Account>();
    objlist.add(new Account());
    return objlist;

You can use any SObject -- doesn't have to be an account.
Yash ShuklaYash Shukla
Nope you cannot initialize your data in execute method. You have to override the start method either by returning and empty list or by querying the records and returning the database,queryLocator instance