Play Around Salesforce Batch Apex And Schedule Apex

Batch Apex

Batch Apex classes are beneficial if the task is something to run large jobs like thousands or millions which is exceeded than normal processing limits. Through batch class one can process the records asynchronously. The specific advantages for using the batch class :

  • If any batch failed and not processed successfully then other successful batch transactions not rolled back.
  • A new transaction starts with new governor limits which make sure that your code runs under their governor limits.

There are three methods which are used in batch class

  • Start : In start method the records are collected which are further utilize in execute method. Here we can use QueryLocator and Iterable for records retrieval and we can query upto 50 million records by queryLocator that bypassed the governor limit whereas in Iterable the governor limit for fetching records through SOQL is still enforced.
  • Execute : The data under every batch get processed within execute method. The default size of batch is 200 records. This method has reference of Database.BatchableContext object and a list of sObjects i.e List<sObject>. By using Database.QueryLocator we can use returned list.
  • Finish : This method is used for post processing operations and it calls once all batch get processed.

Syntax :


For executing batch Class write below code in the developer console, where 1 signifies the no. of records in a batch you can change this value according to requirement.

Schedule Apex

Schedule apex classes let you schedule the run of your apex classes at the specified time so that the class can run without a delay. An apex class that implements the Schedulable interface for the class determines Schedule apex class. By using System.schedule the method we can schedule a run of an instance of the class at the specified time.

Syntax :

Example :

We can schedule jobs by two different ways:


  • By Scheduling a Job from the UI.
  1. From Setup, enter Apex in the Quick Find box, then select Apex Classes.
  2. Click Schedule Apex.
  3. For the job name, enter something like Daily Oppty Reminder.
  4. Click the lookup button next to Apex class and enter * for the search term to get a list of all classes that can be scheduled. In the search results, click the name of your scheduled class.
  5. Select Weekly or Monthly for the frequency and set the frequency desired.
  6. Select the start and end dates, and a preferred start time.
  7. Click Save
  • By Using code in developer console or anyplace inside code.

Thanks For Reading!!
Happy Salesforce!!


Leave a Reply


We're not around right now. But you can send us an email and we'll get back to you, asap.


About Us

Forcetalks is a Salesforce collaboration platform for coders & developers, geeks & nerds, consultants & business heads, admins & architects, managers & marketers and of course the business owners. A community where you can learn from, where you can contribute to. For you. For Salesforce. Read More...

Copyright 2020 Forcetalks. All Right Reserved.

Log in with your credentials


Forgot your details?