Secure the Application
By the end of this lesson, you'll be able to:
- Apply Module 28's security model consistently across all four objects
- Ensure a Support agent cannot see Time_Entry__c data they have no business seeing
- Verify sharing rules match the actual cross-departmental access requirements
Prerequisites: "Add Integrations"
Different roles, different legitimate access needs
A Sales rep should see Project__c.Health__c but has no legitimate need to see Time_Entry__c (internal Delivery hours logged against a project) or the details of every Support_Case__c. A Support agent needs to see Support_Case__c and enough Project__c context to do their job, but not necessarily Time_Entry__c either. This is a genuinely more nuanced access picture than Module 42\'s banking system, where essentially every field mattered to the account owner uniformly.
Enforcing this through the selector layer, consistently
public with sharing class TimeEntrySelector {
public List<Time_Entry__c> selectByProjectId(Id projectId) {
return [
SELECT Id, Hours__c, Logged_By__c
FROM Time_Entry__c
WHERE Project__c = :projectId
WITH SECURITY_ENFORCED
];
}
}
Because every query in this project already flows through Module 43\'s selector layer, with sharing and WITH SECURITY_ENFORCED enforcement is automatic and consistent everywhere — a Support agent without field-level access to Time_Entry__c simply cannot retrieve that data through TimeEntrySelector, regardless of which service or trigger handler happens to call it.
Why the layered architecture pays off again here
If security had instead been enforced ad hoc, scattered across many individual queries the way Module 43\'s Lesson 4 originally warned about, verifying "does every query respect field-level security?" would require auditing every call site individually. Because this project centralized all queries into selectors from the start (Lessons 4 and 7), that audit is instead: "does every selector apply WITH SECURITY_ENFORCED?" — a small, easily verified checklist.
Exercise
As a comment, explain why auditing this project's security is easier than it would have been if every trigger and service wrote its own SOQL queries directly, without a selector layer.
Show hint
Think about how many places you would need to check in each scenario.
Secure the Application Quiz
My Notes
Log in to keep private notes on this lesson.
Questions about this lesson
No questions yet — be the first to ask.
Log in to ask a question about this lesson.
Summary
This lesson applies Module 28's security discipline to a genuinely cross-departmental application, where different roles legitimately need different levels of access to the same shared Project__c hierarchy — a more nuanced security scenario than any single-department project in this course faced before.