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
Bhaskar ChowdaryBhaskar Chowdary 

Batch Apex

This is Bhaskar i am practicing SFDC i want to learn SFDC

 

How to use batch apex i am using this below code just copy and paste in apex classes page and runs it >  it did not save

Apex Class Edit  

 
Error: Compile Error: Invalid type: CustomAccountIterable at line 3 column 19

 

error is came please any send how to use batch apex when we use batch apex to my mail id

 

:: bhaskar.anumolu@gmail.com::

9652964411

 

 

global class batchClass implements Database.batchable{
   global Iterable start(Database.BatchableContext info){
       return new CustomAccountIterable();
   }     
   global void execute(Database.BatchableContext info, List<Account> scope){
       List<Account> accsToUpdate = new List<Account>();
       for(Account a : scope){
           a.Name = 'true';
           a.NumberOfEmployees = 70;
           accsToUpdate.add(a);
       }
       update accsToUpdate;
   }     
   global void finish(Database.BatchableContext info){     
   }
}

souvik9086souvik9086

Hi,

 

You have to write dynamic query within Start method and then do the return via

Database.QueryLocator(DynamicQuery);

 

For reference please go through this

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_batch_interface.htm

 

If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.

Thanks

puneet28puneet28

Hi Bhaskar/Souvik,

As you can see in the link provided by Souvik,
The start method collects the records or objects to be passed to the interface method execute.
It returns either a Database.QueryLocator object or an iterable that contains the records or objects being passed into the job.

In your case, you will have to use Custom Iterators
Heres more info on the same
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_iterable.htm