Detect Recursive Trigger Chains Between Salesforce Objects
Last updated: November 29, 2026
Quick Overview
Given a map from each sObject to the objects its triggers or record-triggered flows update, and a starting object, return one cycle of objects reachable from the start (as a path that begins and ends on the same object), or an empty list if saving the start record cannot cause recursion.
Salesforce
November 29, 20260
0
0 solved
Given a map from each sObject to the objects its triggers or record-triggered flows update, and a starting object, return one cycle of objects reachable from the start (as a path that begins and ends on the same object), or an empty list if saving the start record cannot cause recursion.
Recursive triggers are a classic Apex pain point: an Opportunity update touches Quotes, whose lines roll back up to the Opportunity, and the transaction hits limits. Salesforce onsite coding rounds like problems drawn from the platform, and this one tests directed-graph cycle detection with path reconstruction, ideally iteratively so deep automation chains cannot overflow the stack.
What the Interviewer Expects
- Model objects as nodes and automation updates as directed edges
- Use three-color DFS so finished nodes are not revisited and a gray hit means a back edge
- Reconstruct the actual cycle path, not just a boolean
- Handle self-loops such as a Lead trigger updating Lead
- Explain why an iterative DFS is safer than recursion here
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you return every object involved in any cycle in the org, not just one?
- Some updates only fire when a field changes. How could you model conditional edges?
- How would you suggest the minimum set of edges to cut so the graph becomes acyclic?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: rules as dict[str, list[str]] and start. Output: a list like ['Opportunity','Quote','QuoteLine','Opportunity'], or []. Only cycles reachable from start matter, because only those ca...
High-Level Design
Standard three-color DFS. White is unvisited, gray is on the current path, black is fully explored. Hitting a gray node means a back edge, so the cycle is the slice of the current path from that node ...