Skip to main content

Posts

Async Apex

Explore practical guides and implementation patterns for this topic.

Salesforce Async Apex Explained: The "Who Can Call Whom" Matrix
Salesforce Basics

Salesforce Async Apex Explained: The "Who Can Call Whom" Matrix

๐Ÿ’ฌ In plain words: Navigating asynchronous Apex is all about knowing who is allowed to call whom. A Queueable can chain itself, and a Batch can start a Queueable . However, a @future method is a dead end—it cannot call another @future , and a Batch cannot call a @future . Memorizing this simple matrix eliminates an entire category of runtime crashes. Key Points at a Glance The Future is a Dead End: You cannot call a @future method from any other async context (Batch, Queueable, or another Future). Queueable is the Swiss Army Knife: You can enqueue a Queueable from a Trigger, a Batch execute() or finish() , and even chain it to another Queueable. Batch Chaining: You can legally chain a new Batch job, but only from the finish() method of the current Batch. Callout Rule: Callouts require the correct marker ( callout=true or Database.AllowsCallouts ) and can never occur after a DML operation in the same transaction. ๐Ÿ“Œ Real...
Master Salesforce Scheduled Apex & The Flex Queue
Salesforce Basics

Master Salesforce Scheduled Apex & The Flex Queue

๐Ÿ’ฌ In plain words: Scheduled Apex acts as your org's cron job: "Run this class every night at 2 AM." The Apex Flex Queue is the waiting room for these jobs. Because Salesforce only allows 5 batch jobs to run concurrently, up to 100 additional jobs can sit patiently in the Flex Queue until a slot opens up. You schedule the class, and the platform handles the waiting room. ๐Ÿ“Œ The 2 AM Reminder Example: You need to send subscription renewal reminders daily at 2:00 AM. You write a Schedulable class and set a cron expression: 0 0 2 * * ? . When 2:00 AM hits, what if 9 other heavy batch jobs are already running? No problem. Your reminder job enters the Flex Queue (which holds up to 100 jobs) and waits until one of the 5 active slots becomes available. ๐Ÿง  Memory Aid: The Alarm Clock + The Waiting Room Scheduled Apex is the alarm clock . The Flex Queue is the waiting room (100 seats, 5 doors). Core Concept: How Scheduled Ap...
Master Salesforce Queueable Apex: Chaining, Finalizers, and Cursors
Salesforce Basics

Master Salesforce Queueable Apex: Chaining, Finalizers, and Cursors

๐Ÿ’ฌ In plain words: Queueable Apex is Salesforce's modern asynchronous worker. Unlike older methods, it accepts complex objects as parameters and returns a trackable Job ID. Best of all, it allows for chaining—one job can trigger the next, passing the baton like a relay race. By attaching a Transaction Finalizer , you build a safety net that guarantees specific code will run (for logging or retrying) even if the main job crashes. ๐Ÿ“Œ The Order Fulfillment Example: Imagine an order ships. Job 1 calls the courier API. Once complete, it enqueues Job 2 to update the inventory system. Job 2 then enqueues Job 3 to email the invoice. This is an organized relay race where every runner gets a fresh set of governor limits. If Job 2 crashes due to a limit exception, its Transaction Finalizer catches the failure, logs it, and re-queues the job to try again. ๐ŸŽฌ Real-Life Application: The Relay That Never Drops the Baton A company needs to process b...
The Ultimate Guide to Salesforce Batch Apex: Processing Millions of Records Safely
Salesforce Basics

The Ultimate Guide to Salesforce Batch Apex: Processing Millions of Records Safely

๐Ÿ’ฌ In plain words: Batch Apex is the heavy-duty freight train for processing millions of Salesforce records. It grabs a massive query, chops it into smaller chunks (default is 200 records), and processes them piece by piece. Because each chunk gets a fresh set of governor limits, you can safely update massive datasets. When volume is the problem, Batch Apex is the solution. ๐Ÿ“Œ The 4 Million Customer Example: Imagine you need to recalculate loyalty points for 4 million customers. Batch Apex queries them all at once (using a QueryLocator to stream up to 50 million rows safely) and processes them 200 at a time. That creates 20,000 mini-transactions, each with its own limits. If chunk #47 encounters an error and fails, the other 19,999 chunks will still commit successfully. ๐ŸŽฌ Real-Life Application: 3 Million Rows Before Breakfast A sudden price change means you need to recalculate the fuel surcharge on 3 million Delivery records overnight. ...
Topic LWC
Lightning Web Components

How to Retrieve & Monitor Scheduled Jobs in Salesforce LWC (CronTrigger Guide)

In plain words: A Scheduled Jobs Monitor in LWC is a custom dashboard component that retrieves and displays active background cron jobs from your Salesforce org. By querying the CronTrigger and CronJobDetail objects in Apex, developers can display upcoming run times, execution states, and cron expressions directly on admin homepages or dev utilities without navigating to Salesforce Setup. In enterprise Salesforce environments, scheduled Apex jobs handle nightly data syncs, automated batch runs, cleanup utilities, and reporting calculations. While administrators can view scheduled jobs in Salesforce Setup under Scheduled Jobs , building a dedicated Lightning Web Component allows teams to embed live job monitoring into custom DevOps consoles, monitor execution health in real time, and trigger manual abort or rescheduling routines on demand. 1. Understanding the Scheduled Job Data Model When you schedule an Apex class using System.schedule() or the declarativ...