function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Phuc Nguyen 18Phuc Nguyen 18 

Can a apex class sharing rule control access on lightning page

I was wondering.  Can an apex class(sharing class) be used to set the fields on a standard lightning record page read or edit based on a formula field on the record?  I create a checkbox that is set to true if the logged in user is not equal to a field on the record. Just wondering if an apex class can be used since I was unable to used a sharing rule.
Thank you,
P
ShirishaShirisha (Salesforce Developers) 
Hi Phuc,

Greetings!

Yes,you can achieve this through Apex by checking the access level of the current user by querying as below:


SELECT RecordId, HasEditAccess FROM UserRecordAccess WHERE UserId = [single ID] AND RecordId = [single ID]

Reference:https://salesforce.stackexchange.com/questions/175/can-i-find-out-if-the-current-user-has-access-to-a-record-without-querying

Once,you check it based on the profile of the user you can set the FLS as well,Please find the sample code here (https://developer.salesforce.com/forums/?id=9060G0000005hnvQAA).

Kindly let me know if it helps you and close your query by marking it as best answer so that it can help others in the future.

Warm Regards,
Shirisha Pathuri