This guide walks through 3 Queueable Apex for chainable, stateful asynchronous processing. Each entry below includes the full problem statement, the governor-limit and best-practice constraints it's testing, and a numbered approach to solving it — then you can open the same problem in ApexArena's browser-based Apex editor and get instant pass/fail feedback against real test cases.
Write OpportunityHealthScoreQueueable that implements Queueable
and recalculates a custom Health_Score__c field on a set of Opportunities.
Amount ≥ 50,000CloseDate ≥ today (not in the past)StageName is 'Proposal/Price Quote' or
'Value Proposition'StageName is 'Closed Won'Queueable.Set<Id> opportunityIds.execute(QueueableContext context): guard empty input, query Opps,
compute score, bulk update.isEmpty() before DML.System.enqueueJob(new OpportunityHealthScoreQueueable(ids));Implement the chained Queueable pattern with two classes:
AccountTierQueueable — sets Revenue_Tier__c on Accounts,
then chains to ContactTagQueueable.ContactTagQueueable — sets Contact_Segment__c = 'Processed'
on related Contacts.Queueable.Set<Id> accountIds via constructor.AccountTierQueueable.execute(): update Revenue_Tier__c per scoring rules,
then call System.enqueueJob(new ContactTagQueueable(accountIds)) guarded
by !Test.isRunningTest().ContactTagQueueable.execute(): set Contact_Segment__c = 'Processed'
on all Contacts whose AccountId IN :accountIds.if (!Test.isRunningTest()) — you cannot enqueue from
within a Queueable during test execution without wrapping in
Test.startTest()/stopTest().Write OpportunityStageUpdateQueueable that updates a batch of Opportunities
to a target StageName. If the DML fails, re-enqueue itself up to
MAX_RETRIES = 3 times.
Queueable.(List<Id> opportunityIds, String targetStage, Integer retryCount).private static final Integer MAX_RETRIES = 3.execute(): guard empty input and blank stage; skip records already at the
target stage; wrap DML in try-catch; on failure re-enqueue if
retryCount < MAX_RETRIES guarded by
!Test.isRunningTest().retryCount + 1 — never modify the field directly before the retry call.Write and run real Apex code right in your browser — instant pass/fail feedback, best-practice linting, and governor limit monitoring. No Salesforce org needed.
Create Free Account → Explore All ProblemsApexArena is a free, browser-based Salesforce Apex coding practice platform covering every major topic tested on the Salesforce Platform Developer I (PD1) and Platform Developer II (PD2) certification exams. All problems run directly in your browser with instant pass/fail feedback, best-practice linting (SOQL in loops, DML in loops, empty catch blocks), and governor limit monitoring — no Salesforce Developer Edition org required.
Related tutorials: Apex Triggers · SOQL · Batch Apex · Interview Q&A · Governor Limits