Salesforce Decode
Salesforcedecode
Back to questions
ApexAdvancedselectorfflibpatterns

Apply Selector layer pattern for SOQL centralization

Real World Scenario

SOQL duplicated across 15 classes querying Account with slightly different field lists.

Expected Answer

• AccountSelector class with methods per use case • Consistent field sets preventing field absence bugs • Mock selectors in service layer unit tests • Security enforced in selector with USER_MODE • Avoid SOQL outside selector except ad-hoc admin tools • Selector returns List or Map as appropriate

Follow-Up Questions & Answers

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

Main difference: use case and scale. AccountSelector class with methods per use case. Consistent field sets preventing field absence bugs. Pick based on your integration pattern and team capability. Selectors are SOQL gatekeepers—one place to add FLS and field changes. Optimize for scale and operational observability.

Architect Perspective

Selectors are SOQL gatekeepers—one place to add FLS and field changes.