ForceChallenges
ProblemsDailyNotesInterview
Sign in

Practice

All problemsSOQL practiceApex trigger challengesDaily challengeOpportunityTrigger.oldMapBefore UpdateBulkificationContactValidationGROUP BYSemi-JoinAccountBefore Insert

Interview questions

All questionsAdminAdministrationApexApex TriggerAsync ApexDevelopmentField ServiceField ServiceIntegrationLwc

By company

DeloitteSalesforceAccentureInfosysPwCCognizant

Learn

Study notes

ForceChallenges

AboutContact usPrivacy PolicyTerms of ServiceFor AI assistants (llms.txt)
© 2026 ForceChallenges · Salesforce SOQL & Apex trigger practice
Apex questions5 of 41
ApexMedium 2 min read

How can you track the execution identifier returned when enqueueing a Queueable Apex job?

Answer

Basics: Queueable jobs run later, so the Id is your only handle. Saving it on a record or log lets you answer "did it finish, and did it fail?"

How it works:

  1. Id jobId = System.enqueueJob(new MyJob(...));
  2. Persist it (a log record, a field on the parent, or a platform event payload).
  3. Query AsyncApexJob by Id: Status (Queued, Processing, Completed, Failed, Aborted), NumberOfErrors, ExtendedStatus, CreatedDate, CompletedDate.
  4. Inside the running job, QueueableContext.getJobId() gives its own Id.

Advanced / deep dive: AsyncApexJob is a sampled, short-lived record, not a durable audit log, so copy key outcomes into your own object. A Finalizer (System.attachFinalizer) runs after the job even on unhandled exception or limit failures and receives a FinalizerContext with getResult() (SUCCESS or UNHANDLED_EXCEPTION), getException() and getAsyncApexJobId(); this is the best place to update the log record to Failed or to enqueue a retry. DML in the same transaction that enqueues the job is not tied to the job; if the transaction rolls back after enqueueJob, the job is also not run. Using AsyncOptions (delay, duplicate signature) is available in newer API versions; verify availability. Remember to bulkify the logging DML.

Code / config example:

apex
Id jobId = System.enqueueJob( (accountIds));
insert  (Job_Id__c = jobId, Status__c = , Type__c = );


   [
    SELECT Status, NumberOfErrors, ExtendedStatus
    FROM AsyncApexJob    :jobId
];
Practice SOQL & Apex
PreviousHow can you trigger subsequent asynchronous jobs inside the finish method of a Batch Apex class?Next How does Asynchronous Apex resolve Mixed DML exceptions involving setup and non-setup objects?

More Apex questions

  • How do you pass runtime parameters into a Batch Apex class prior to execution?
  • What are the primary differences in governor limits between synchronous transactions and asynchronous Apex executions?
  • How do you prevent recursive asynchronous job enqueuing triggered by recursive database DML updates?
  • How do you handle partial success and error isolation when performing DML updates in Batch Apex?
  • What are the concurrency and maximum limit constraints associated with Scheduled Apex jobs in an org?
new
SyncAccountsJob
new
Job_Log__c
'Queued'
'AccountSync'
// Later, in a monitor
AsyncApexJob
j
=
WHERE
Id
=

Hidden gotchas & must-remember points:

  • The returned Id is an AsyncApexJob Id, not a CronTrigger Id.
  • If the enclosing transaction rolls back, the job does not start.
  • AsyncApexJob rows are purged after some days, so store outcomes yourself.
  • Finalizers are the only reliable way to catch limit-exception failures.
  • Only 50 jobs can be enqueued per sync transaction; 1 from within a queueable.
  • Test context returns an Id but the job runs only at stopTest().

Best practice: Log the Id at enqueue time and update the log from a Finalizer.

ApexAsynchronous ApexQueueable Apex