ApexAdvancedvalidationformularules
Implement row-level formula and validation in Apex for complex rules
Real World Scenario
Validation rules cannot express cross-object discount cap requiring query of related Quote lines.
Expected Answer
• Trigger or before-save Flow calling validation service
• AddError on specific field with clear message
• Bulk validate all records in trigger.new collection
• Mirror rule in Apex REST API for headless channel parity
• Document rules living in Apex vs declarative for admins
• Performance test validation with 200 record bulk
• Avoid SOQL per record in validation—query once
Follow-Up Questions & Answers
Click to expand — each follow-up includes a direct, interview-ready answer
Main difference: use case and scale. Trigger or before-save Flow calling validation service. AddError on specific field with clear message. Pick based on your integration pattern and team capability. When declarative fails, centralize imperative validation—do not scatter across triggers and controllers. Optimize for scale and operational observability.
Architect Perspective
When declarative fails, centralize imperative validation—do not scatter across triggers and controllers.