Posts

Showing posts with the label Batch Apex

Batch Apex vs Queueable Class in Salesforce

Image
Both Batch Apex and Queueable Apex are used for asynchronous processing in Salesforce, but they have different use cases and characteristics. Let's define each and provide an example with sample code for both: Batch Apex: Batch Apex allows you to process large data sets by breaking them into smaller batches, which are processed asynchronously in the background. Batch Apex is designed for long-running processes and can handle millions of records efficiently. Use Cases for Batch Apex: Large-scale data processing, such as data cleansing, data migration, or data aggregation. Complex calculations or transformations on a large volume of records. Integration with external systems that involve processing large data sets. Example : Suppose you have a requirement to update the status of all opportunities with a certain criteria asynchronously. You can use Batch Apex to process these records in batches. public class OpportunityBatch implements Database.Batchable<sObject> {     publ...

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