In this article, we will discuss how to allow only the record owner or system administrator to edit certain items in Salesforce.
This setting can be achieved by writing a formula in the input rule as shown below. Here we will explain how to make an item with the API reference name “Sample__c” editable only by the record owner and the system administrator.
First, copy the item API reference name of the target object. Then, select “Input Rules”.
Then, enter the following as shown in the figure below.
AND(
ISCHANGED( Sample__c ),.
NOT(
OR(
$Profile.Name = "System Administrator",.
OwnerId = $User.Id
)
)
) )
The elements of the above formula are explained one by one.
AND(...)
ISCHANGED( Sample__c ):Raises an error if all conditions are True.ISCHANGED( Sample__c )
:
True if theSample__c
field is modified.NOT(...)
True if the internal condition is not true.OR(...)
):True if any of the internal conditions are True.$Profile.Name = "systemadmin
“: True if the current user’s profile name is “systemadmin”.OwnerId = $User.Id
: True if the record’s owner ID matches the current user ID.
Thus, the formula can be interpreted as follows
Sample__c
if the field is modified.- If the current user is neither the “system administrator” nor the owner of the record
- an error is generated.
To summarize, this formula means that if a user other than the system administrator or record owner attempts to modify a Sample__c
field, an error will be generated.
In this explanation, we have set it up so that the “system administrator” can also edit the item. This is to prevent the record owner from being unable to edit an item due to sudden absence or resignation of the record owner. After making various assumptions, let’s find the best way to set up the system!