● Shipment records that belong to their teams can be seen by other users.
● Shipment amount should be visible only by managers, but sales reps are able to view it.Which two features did the development team miss that is causing the problems?
Choose 2 answers.
Show answerHide answer
Correct answer: B, D Use With Sharing keyword in Apex classes to enforce sharing rules evaluation.Use isAccessible() method in Apex classes to check field accessibility
Explanation
ExplanationIn Salesforce, custom Lightning components often retrieve data via Apex controllers. By default, Apex executes in system mode, bypassing the current user's sharing rules, object permissions, and field-level security. For a private custom object like Shipment, developers must manually enforce record-level sharing and field accessibility in Apex to align with profile settings and OWD, preventing unauthorized data exposure.
✅ Correct Option: B. Use With Sharing keyword in Apex classes to enforce sharing rules evaluation.
The "with sharing" keyword on an Apex class declaration forces queries to respect the organization's sharing model—including private OWD, role hierarchy, sharing rules, and manual shares. Without it, Apex returns all records visible in system context, allowing users to view shipments owned by other teams despite restrictions.
✅ Correct Option: D. Use isAccessible() method in Apex classes to check field accessibility.
Apex does not automatically enforce Field-Level Security (FLS). To protect sensitive fields like Shipment Amount, code must use Schema describe methods (e.g., Shipment__c.Shipment_Amount__c.getDescribe().isAccessible()) before querying or exposing the field. Omitting this check reveals restricted fields to all users via the component.
❌ Incorrect Option: A. Use runAs in test class to enforce user permissions and field-level permissions.
The System.runAs() method is used exclusively in test classes to simulate execution under different user profiles and validate security behavior. It verifies enforcement during testing but has zero impact on production runtime, where actual data visibility issues occur.
❌ Incorrect Option: C. Use isSharable keyword in Apex classes to assure record visibility.
No such "isSharable" keyword exists in Apex. Record-level visibility is managed solely through class declarations like "with sharing," "without sharing," or "inherited sharing"—not by any field-check or fictional keyword.
Summary
Always use "with sharing" in Apex controllers for components accessing private objects to enforce record ownership and sharing. Explicitly validate field accessibility with isAccessible() to honor FLS and hide sensitive data from lower-level users. Testing tools like runAs ensure code quality but don't prevent live security leaks. Proper enforcement aligns custom components with Salesforce's declarative security model for safe data display.
Reference:
Using the with sharing, without sharing, or inherited sharing Keywords
Secure Apex Classes