Posts

Showing posts with the label Apex Scheduler

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...

Asynchronous Apex in Salesforce

Image
Asynchronous Apex in Salesforce refers to executing code asynchronously, meaning that the code is executed in the background without blocking the user interface. Asynchronous Apex is typically used for long-running or resource-intensive processes that would otherwise exceed the transaction execution time limits. Queueable Apex Take control of your asynchronous Apex processes by using the Queueable interface. This interface enables you to add jobs to the queue and monitor them. Using the interface is an enhanced way of running your asynchronous Apex code compared to using future methods. Apex Scheduler Batch Apex Future Methods This table lists the asynchronous Apex features and when to use each. Here'r multiple ways for running your Apex code asynchronously. @future Annotation : Methods annotated with @future are queued for execution in a separate transaction. This allows you to perform tasks asynchronously. @future methods can accept parameters and return void, making them suitab...