Salesforce Developer Interview Question

A trigger starts hitting the Apex CPU time limit after new automation is added. How do you investigate?

What the interviewer is probing, how to structure your answer, and a spoken example you can adapt.

Quick answer

Look at the whole transaction, because CPU time is shared by every trigger, flow, validation and package on the save. Reproduce with a bulk test and a detailed debug log, find where the time goes, and check for nested loops, repeated work, recursion and automation running twice. Fix the expensive code, replace nested loops with maps, stop duplicate execution, and move heavy work that users need not wait for to asynchronous Apex.

Why interviewers ask this

CPU limit errors are harder to diagnose than query limits, because the cost is spread across every piece of automation in the transaction. The interviewer wants to see that you look at the whole save rather than blaming the newest change, use logs to find where the time goes, and recognise the usual culprits such as nested loops, recursion and duplicate processing. Moving genuinely heavy work out of the synchronous path shows good judgement.

How to structure your answer

  • Explain that CPU time is shared by everything in the transaction.
  • Reproduce and measure where the time goes.
  • Check for nested loops, recursion and duplicate execution.
  • Fix, then move heavy work to asynchronous processing.

Example answer

Spoken example, first person

The new automation triggered the failure, but it is not necessarily the cause, because CPU time is one ten second budget shared by everything that runs on the save. The newest flow may simply be the one that tipped it over. So I reproduce it with a bulk test of two hundred records, capture a debug log with profiling detail turned up, and look at where the time actually goes. The usual culprits are nested loops, such as looping over every opportunity for every account instead of building a map once, repeated work like three handlers processing the same query results, and recursion, where a field update fires the triggers again and everything runs twice. Flows count too. On one org the real problem was an old trigger rerunning all its logic on every update, even when no relevant field had changed. Adding a check that only processes records whose key fields actually changed cut CPU time by more than half. Anything heavy that users do not need to wait for went to a Queueable.

Walking into this interview soon? GhostPilot listens to your live call, spots the question the moment it is asked, and puts a structured answer on your screen in real time. Try it on your next mock, or grab a $29 Session Pass, no subscription, for the real thing.

See how it works

Follow-up questions to expect

  • Does time spent waiting on database queries count towards the CPU limit?
  • How would you process only the records whose relevant fields changed?
  • When would you move logic from a trigger into asynchronous Apex?

Related salesforce developer questions

Your interviewer will ask their own version of this. Paste your actual job description into the free Question Predictor and get the 20 questions that role is most likely to ask, with what each one is really probing.

Predict my questions

Rehearse the hard questions before they are asked

Practise with a live copilot, then walk in ready. A $29 Session Pass gets you through the interview with no subscription and no lock-in.

Get GhostPilot