+ Start a Discussion
viswsanathviswsanath 

How to handle more records in background process in Batch apex?

Hi All,

I have no idea on batchapex , Any one can  be explain me on how to handle bulk records in background process in batch apex?

Regards,
Viswa.
AshlekhAshlekh
Hi,

Please refer this link which have same question regarding Batch.
https://developer.salesforce.com/forums/?id=906F00000008r66IAA

This is a blog which will provide you more information about Batch
http://blog.shivanathd.com/2013/01/how-to-write-batch-class-in.html

-Thanks
Ashlekh Gera
Tejpal KumawatTejpal Kumawat
Hello Viswa,

Apex batch process records in Chunk(like 200 records in single chunk). So you need to pass record size when you run your batch.

Like example
global class UpdateAccountFields implements Database.Batchable<sObject>{
   global final String Query;
   global final String Entity;
   global final String Field;
   global final String Value;

   global UpdateAccountFields(String q, String e, String f, String v){
             Query=q; Entity=e; Field=f;Value=v;
   }

   global Database.QueryLocator start(Database.BatchableContext BC){
      return Database.getQueryLocator(query);
   }

   global void execute(Database.BatchableContext BC, 
                       List<sObject> scope){
      for(Sobject s : scope){s.put(Field,Value); 
      }      update scope;
   }

   global void finish(Database.BatchableContext BC){

   }

}
Following code to run batch class from developer console.
 
// Query for 10 accounts
String q = 'SELECT Industry FROM Account LIMIT 10';
String e = 'Account';
String f = 'Industry';
String v = 'Consulting';
Id batchInstanceId = Database.executeBatch(new UpdateAccountFields(q,e,f,v), 5);
For more deatails : https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_batch_interface.htm

Regards
Tej Pal Kumawat
Skype : tejpalkumawat1991

If this answers your question mark Best Answer it as solution and then hit Like!