# What is an Apex Trigger in Salesforce and when should you use it over Flows?

**Topic:** Apex Trigger · **Difficulty:** Easy · **Asked at:** TCS, Infosys, Cognizant · **Tags:** apex-trigger, trigger, fundamentals

Read it on the site: https://www.forcechallenges.com/interview-questions/what-is-an-apex-trigger-in-salesforce-and-when-should-you-use-it-over-flows

## Answer

An Apex Trigger is Apex code that runs automatically before or after DML events (insert, update, delete, undelete) on an object.

**Use a trigger over Flow when:**
- Logic is complex (multi-object, heavy collections, recursion control)
- You need high-volume bulk processing with fine control over governor limits
- You need Apex-only features: Savepoints, Database methods with partial success, callouts via async Apex, Apex Managed Sharing
- You need precise control over before/after context and error handling

**Use Flow when:** the logic is simple, admin-maintainable, and declarative tools (Record-Triggered Flow) cover it. Avoid mixing both on the same object/event without understanding order of execution.

---
Source: ForceChallenges · last updated 2026-10-21
