While developing an Apex class with custom search functionality that will be launched from a Lightning Web Component, how can the developer ensure only records accessible to the currently logged in user are displayed?
Suggested Answer: A
Get Premium DEX-450 Questions
as Interactive Web-Based Practice Test or PDF
Real Exam Format
Detailed Explanations
Instant Access
Get Your Practice Test
25 comments · newest first
RE
Remona
4 months ago
Yes! It enforces sharing rules automatically.
GE
Gearldine
4 months ago
What about using `with sharing` in the class?
BE
Beckie
4 months ago
Agreed! It helps filter records based on user permissions.
PA
Patti
5 months ago
I think using the `UserRecordAccess` object is key here.
BL
Blossom
6 months ago
You can also use `with sharing` in your class, right?
RY
Ryann
6 months ago
Really? I didn't know you had to check access like that.
BE
Beatriz
6 months ago
I thought sharing rules would be enough, but this makes sense.
WE
Wei
6 months ago
Totally agree, that's the best way to handle it!
BE
Bettina
6 months ago
Use the `UserRecordAccess` object to check record visibility.
TE
Tennie
6 months ago
Haha, good thing we don't have to worry about security in our code, right? Just display all the records!
CA
Casie
7 months ago
Wrap the SOQL query in a `System.runAs()` block to execute the query as the current user.
HO
Hobert
7 months ago
Leverage the `@AuraEnabled(cacheable=true)` annotation on the Apex method to automatically handle user permissions.
RY
Ryan
7 months ago
Use the `WITH SECURITY_ENFORCED` clause in the SOQL query to ensure only records the user has access to are returned.
EM
Emogene
7 months ago
I feel like we also have to consider the user's profile and roles when determining access, but I can't remember how to implement that in the code.
MI
Milly
7 months ago
There was a practice question about filtering records based on user permissions, and I think we might need to use SOQL queries with the `WHERE` clause for that.
FI
Filiberto
8 months ago
I remember something about using `UserInfo.getUserId()` to filter records, but I can't recall the exact implementation details.
AR
Arthur
8 months ago
I think we need to use the `with sharing` keyword in the Apex class to enforce sharing rules, but I'm not entirely sure if that's enough.
LA
Lamonica
8 months ago
I've done something similar before. I'd use the WITH SECURITY_ENFORCED clause in the SOQL query to automatically apply the user's permissions. Should be a straightforward fix.
PA
Pamella
9 months ago
This seems tricky. I'll need to research how to properly handle user permissions in an Apex class that's called from a Lightning Web Component. Might take some time to figure out the right solution.
TY
Tyra
9 months ago
Okay, I think I've got a plan. I'll use the System.UserInfo class to get the current user's ID, then build a dynamic SOQL query to only return records they have access to.
TH
Thora
9 months ago
Hmm, not sure about this one. Probably need to leverage the user context in the Apex class somehow, but not totally clear on the best approach.
VI
Vilma
9 months ago
I'd start by checking the user's permissions and querying the records accordingly. Might need to use a SOQL query with appropriate filters.
MA
Makeda
3 months ago
Also, consider using sharing rules for better access control.
KI
Kimberely
3 months ago
Definitely! SOQL filters will help narrow down the results.
OD
Odette
3 months ago
I agree, checking user permissions is crucial.