Salesforce Decode
Salesforcedecode
Back to questions
ApexIntermediateperformancemonitoringgovernor-limits

Profile Apex CPU and SOQL in production without debug logs

Real World Scenario

Production debug logs unavailable for all users. Ops needs CPU hotspot identification on Account trigger without enabling full trace.

Expected Answer

• Custom logging at method entry: Limits.getCpuTime(), getQueries() • Log only when threshold exceeded reducing noise • Event Monitoring Apex Execution event if licensed • Transaction Finalizer or Queueable sampling limit snapshots • Compare sandbox replay with production data clone profiling • PMD and static analysis pre-deploy for known anti-patterns • Targeted trace flag on integration user during incident only

Follow-Up Questions & Answers

Click to expand — each follow-up includes a direct, interview-ready answer

Direct answer: Custom logging at method entry: Limits.getCpuTime(), getQueries() Also consider: Log only when threshold exceeded reducing noise In practice: Event Monitoring Apex Execution event if licensed Balance speed of delivery with maintainability.

Architect Perspective

Production profiling needs lightweight instrumentation—do not rely on permanent debug logs.