Salesforce Decode
Salesforcedecode
Back to questions
ApexBeginnerenumsconstantsclean-code

Apply Apex enum and constant patterns for maintainability

Real World Scenario

Status strings scattered as literals cause typos breaking batch filters silently.

Expected Answer

• Public enum OrderStatus { Draft, Submitted, Cancelled } • Constants class for magic numbers and API codes • Switch on enum exhaustive handling compile warnings • Custom Metadata for business configurable values not enums • Map enum to external system codes in integration layer • Code review rejects new string literal status comparisons

Follow-Up Questions & Answers

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

Direct answer: Public enum OrderStatus { Draft, Submitted, Cancelled } Also consider: Constants class for magic numbers and API codes In practice: Switch on enum exhaustive handling compile warnings Keep the solution simple and well-documented for the team.

Architect Perspective

Enums document allowed states—cheap insurance against typo bugs.