0

I have a custom object to apply for leaves (such as Casual, Sick, Unpaid) for the users in my org. I have applied a validation rule to check different users cannot create or edit any record for other users except for the owner. I have used the User Alias for the validation rule and I have created Master-Detailed relationship of the user with the Custom object using Contact and have created a field naming 'Alias' in the Contact object and each user have an unique alias. The validation rule used is: $User.Alias != Contact__r.Alias__c

Now, due to the above rule the System Admin is unable to Reject the leave request for the user. I want the system admin should be able to edit the record submitted by any user for approval and Approve or Reject the record.

Please help me out with this.

2
  • Seems to me a case for Sharing. Make sure these objects have the User as the owner and ensure sharing rules are such that these objects are read only (or even not visible) for anyone who is not the owner. Since Admins typically have "Modify All Data" permissions they won't be restricted from viewing/modifying individual records. Alternatively use role hierarchies and ensure Admins have a role higher in the hierarchy so they can view/modify records belonging to subordinates (the Users).
    – Phil W
    Jun 5 '20 at 10:39
  • 1
    @PhilW Thanks a lot man. Got my answer. Jun 6 '20 at 6:01
1

You can add an additional condition to the validation rule to give system administrators the ability to edit the record:

AND(
    $User.Alias != Contact__r.Alias__c,
    $Profile.Name != 'System Administrator'
)
1
  • Can you please help me make changes to the aforementioned code to restrict the system admin to create any record for other users. The requirement is to allow the system admin to edit the record requested for approval such that the admin can reject or approve the request but should not be allowed to create a record for other users in the org. Jun 6 '20 at 6:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.