ApexAdvancedperformancegovernor-limitscpu
Optimize CPU time when regex and JSON parsing dominate trigger execution
Real World Scenario
Case trigger parses JSON payload and runs regex validation on Description for 200 cases per batch hitting CPU time limit during email-to-case floods.
Expected Answer
• Move heavy parsing to Queueable after insert for non-blocking path
• Compile regex Pattern once in static final variable not per iteration
• JSONParser streaming instead of deserializeUntyped on large payloads
• Early exit when Description blank or format prefix mismatch
• Log Limits.getCpuTime() at method boundaries identifying hot spots
• Batch email ingestion instead of per-email trigger when volume spikes
• Consider Platform Event subscriber for parsing isolated from Case DML
Follow-Up Questions & Answers
Click to expand — each follow-up includes a direct, interview-ready answer
Main difference: use case and scale. Move heavy parsing to Queueable after insert for non-blocking path. Compile regex Pattern once in static final variable not per iteration. Pick based on your integration pattern and team capability. CPU limits bite suddenly at volume—profile trigger at 200 records with realistic payload sizes. Optimize for scale and operational observability.
Architect Perspective
CPU limits bite suddenly at volume—profile trigger at 200 records with realistic payload sizes.