Advanced 25 min read

Monitor Transactions

By the end of this lesson, you'll be able to:

  • Query AsyncApexJob to check the status of enqueued payment jobs
  • Identify orders stuck in a non-final payment status
  • Explain why monitoring matters specifically for a financial process

Prerequisites: "Test with Mocks"

Checking job status directly

List<AsyncApexJob> paymentJobs = [
    SELECT Id, Status, NumberOfErrors, CompletedDate
    FROM AsyncApexJob
    WHERE ApexClass.Name = 'ProcessPaymentJob'
    ORDER BY CreatedDate DESC
    LIMIT 20
];

for (AsyncApexJob job : paymentJobs) {
    System.debug(job.Status + ' - Errors: ' + job.NumberOfErrors);
}

This is Module 38's AsyncApexJob monitoring lesson, filtered specifically to ProcessPaymentJob — a support team could run this (or a scheduled report built on it) to confirm payment jobs are actually completing, not silently stuck.

Finding orders stuck in a non-final status

List<Order__c> stuckOrders = [
    SELECT Id, Status__c, LastModifiedDate
    FROM Order__c
    WHERE Status__c = 'Ready for Payment' AND LastModifiedDate < :DateTime.now().addMinutes(-10)
];

An Order__c still sitting at 'Ready for Payment' more than 10 minutes after being set there suggests something went wrong — the trigger might not have fired, the Queueable job might have failed silently, or an unexpected exception occurred somewhere in the chain. This query surfaces exactly that gap for investigation.

Why this matters more here than in earlier modules

Module 26's revenue rollup or Module 27's leave requests being briefly out of sync is inconvenient; a payment that's silently stuck — neither charged nor clearly failed — is a genuinely serious problem for both the business and the customer. Financial processes specifically deserve active monitoring, not just correct code, because the cost of an unnoticed failure is meaningfully higher.

Exercise

Write a query finding every ProcessPaymentJob AsyncApexJob with a Status of 'Failed'.

Show hint

WHERE ApexClass.Name = 'ProcessPaymentJob' AND Status = 'Failed'

APEX

Monitor Transactions Quiz

1. Why does a payment process deserve more active monitoring than, say, Module 26's revenue rollup?

Log in to submit the quiz and save your score.

My Notes

Log in to keep private notes on this lesson.

Questions about this lesson

No questions yet — be the first to ask.

Log in to ask a question about this lesson.

Summary

This lesson applies Module 38's AsyncApexJob monitoring specifically to this feature — checking that payment jobs actually complete, and identifying orders that might be stuck.