function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
NLTNLT 

How to write the batch job that will query the leads with Lead Status = Converted, Activated In-Store to create the account, contact and other custom object 'BAN' that is associate to the account with 2 required fields BAN__c and Tax ID on lead object

How to write the batch job that will query the leads with Lead Status = Converted, Activated In-Store to create the account, contact and other custom object 'BAN' that is associate to the account with 2 required fields BAN__c and Tax ID on lead object
Sukanya BanekarSukanya Banekar
Hi TNL,
You can create a batch class 
global class batchClass implements implements Database.Batchable<sObject>{
    global Database.QueryLocator start(Database.BatchableContext BC){
       //query on lead object to to get lead with status 
       String query= ;
       return Database.getQueryLocator(query); // execute query
    }

   global void execute(Database.BatchableContext BC, List<sObject> scope){
       list<sObject> lstSobject = new list<sObject>();
       Account acc;
       contact con;
       Ban__c ban;
       for(sobject s : scope){ // lead records from above method
		acc= new Account();
		con= new Contact();
		ban= new BAN__C();
		//insert account
		acc.Name= // give name ; 
		//other field you want to create in acc
		lstSobject.add(acc);
		//insert contact
		con.LastName= // give name ; 
		con.AccountId= acc.id;
		//other field you want to create in con
		lstSobject.add(con);
		//insert BAN__C
		ban.Tax__c= s.Tax__c;
        ban.accountId= acc.id;
        lstSobject.add(ban);		
 
       }
	   if(lstSobject <> NULL && !lstSobject.isEmpty()){
		insert lstSobject;
	   }
    }
	global void finish(Database.BatchableContext BC){
	}
}

Also, You can schedule this batch.

Let me know if this helps you to solve your problem.

Thanks,
Sukanya Banekar