Posts

Showing posts from May, 2016

Salesforce Cron expression for Scheduling the Job

Image
In Salesforce, you can use cron expressions to schedule jobs to run at specific times or intervals. Cron expressions are strings comprised of six or seven fields that represent various components of time (seconds, minutes, hours, days, months, and optionally, years).  Apex Scheduler Note Salesforce schedules the class for execution at the specified time. Actual execution can be delayed based on service availability.The System.schedule method uses the user's timezone for the basis of all schedules. Here's the format: Seconds Minutes Hours Day_of_month Month Day_of_week Optional_year The following are the values for the expression: The special characters are defined as follows: The following are some examples of how to use the expression. Here are some examples of cron expressions commonly used for scheduling jobs in Salesforce: Every day at midnight: 0 0 0 * * ? Every hour: 0 0 * * * ? Every 15 minutes: 0 0/15 * * * ? Every weekday at 9 AM: 0 0 9 ? * MON,TUE,WED,THU,FRI Every 30...

Salesforce Batchable Apex and Schedulable Apex with an Example

Salesforce provides two powerful features for executing code asynchronously: Batchable Apex and Schedulable Apex. These features allow developers to perform complex data processing tasks, integrations, or other long-running operations without impacting the user interface or causing performance issues. Below, I'll explain each feature along with an example for better understanding. Batchable Apex: Batchable Apex allows you to process large data sets in smaller, more manageable batches. It is particularly useful when dealing with large volumes of records that cannot be processed synchronously due to Salesforce's governor limits. Here's an example of how Batchable Apex works: // Example Batchable Apex class global class MyBatchableClass implements Database.Batchable<sObject> {          global Database.QueryLocator start(Database.BatchableContext BC) {         // Query the records you want to process         return Datab...