How to create a formula specific to the running user in Salesforce?

Question
How can I edit a field without triggering validation rules for a specific user in Salesforce?
I have a requirement where a particular field should be editable by a specific user without causing the validation rules to fire. If you are wondering how to create a formula specific to the running user in Salesforce, I initially tried using a formula like LastModifiedId != '005000000000000AAA'
to exempt the user, but the validation rules still triggered. Upon investigation, I realized that the LastModifiedId
does not update until the record is saved, causing the validation to still fire.
Is there a workaround or a method to check the user who is currently editing the record in order to bypass the validation for that specific user? Maybe a solution for creating a formula specific to the running user in Salesforce can help.
CRS Info Solutions offers top Salesforce Training in Ahmedabad, including real-time projects, certification support, and interview coaching. Their hands-on approach ensures you’re fully job-ready!
Answer:
There are several approaches you can take to solve this issue, which I will list in order of preference. These methods can be implemented in Salesforce wherever merge fields are supported. Each of these methods can be used to create a formula specific to the running user in Salesforce:
1. Create a Custom Permission:
You can use a Custom Permission to check if a user has a specific permission, thus exempting them from validation. You can reference this permission in a formula field or validation rule as follows:
$Permission.My_Custom_Permission__c
Steps:
- Create a Custom Permission.
- Add it to a Permission Set.
- Assign the Permission Set to any user you want to exempt from the validation rule.
2. Hierarchy Custom Setting:
If you find the Custom Permission approach unsuitable, another method is to use a Hierarchy Custom Setting. This lets you define which users are exempt based on custom logic. Here’s how you can reference it in a formula:
$My_Hierarchy_Setting__c.Is_Exempt_From_Validation_X__c
Steps:
- Create a Hierarchy Custom Setting.
- Add an exemption field (e.g.,
Is_Exempt_From_Validation_X
). - Set the Org Wide Default for this field to
false
. - Set the value to
true
for any user you wish to exempt from validation.
3. Alias:
A simpler approach can be checking against the user’s Alias. This is straightforward and works well in most environments. You can reference it like this when creating your specific Salesforce formula.
$User.Alias = "analias"
4. Username:
If checking against the Alias doesn’t suit your needs, you can instead check the Username with a formula like:
BEGINS($User.Username, "user@example.com")
This method is less clean than checking the Alias but can still be useful in specific scenarios when determining how to create a formula specific to the running user.
5. User Id:
The least clean option would be to check directly against a user’s Id
:
$User.Id = "00550000000lxVg"
This approach is the least flexible and should only be considered if the above options don’t work for your use case.
Each of these methods has its pros and cons. Custom Permissions provide a clean and scalable way to exempt users, but if you prefer a more dynamic solution, Hierarchy Custom Settings or user-specific fields like Alias and Username might be more appropriate.
See also: Sales Process and Forecasting in Salesforce
Real-Time, Project-Based Salesforce Training in Ahmedabad
Our Salesforce training provides an immersive, hands-on experience to help you build the skills required to excel in the CRM industry. Covering crucial areas like Salesforce Admin, Developer, and AI, the course blends theoretical learning with practical applications. Through live projects and assignments, you’ll develop the expertise to address complex business problems using Salesforce solutions. Experienced instructors offer both technical training and valuable industry insights to guide you.
In addition to technical training, our Salesforce Training in Ahmedabad, offers personalized mentorship, exam preparation, and interview coaching to give you an edge in a competitive job market. You’ll gain access to comprehensive study materials, hands-on project experience, and continuous support throughout the program. By the end of the course, you’ll be ready for certification exams and equipped with practical skills that employers seek. Start your Salesforce career now and discover exciting career opportunities! Join our FREE demo class today!
Take the first step towards your Salesforce career and explore amazing job prospects! Sign up for a FREE Demo now!