Many time we have some requirement in Approval Process field Criteria, Workflow Entry Criteria and Validation rules where some checks are required specific to users.

For e.g.

  1. Take Some workflow action(Email Alert/Field Update/etc) if owner of a record is "User A".
  2. Only enter in approval process if Owner of a record is "User A" or "User B".
  3. Validation rule to allow only two users ("User A" and "User B") to update record.

Above conditions are rare scenarios and users are not part of any specific groups, profiles, roles.

So, we need to use hard coded "user name", "user alias" of these users into criteria.

My question is:

Is it ok to hard code user 's "User Name" or "User Alias" in Approval Process/Workflow Entry criteria and Validation rules, where we can't achieve it by using a public group/profile/role?

I think there is nothing wrong because this requirement are for individual user(s). Also, admin can easily change the users (filter criteria) in future without any deployment.


As per my opinion,

We should not use name/alias, try to use IDs because user can change their names and alias by themselves. (For sandbox, I keep my name-sandboxname as the name to identify which sandbox I am working). In workflow we should use created by "id" instead of "name".
Regarding the hard-coding of user ids or name in WF /approval process, try to avoid it if you have any other alternative.
Otherwise, you need to change all the hard coded references when you make that user inactive.

| improve this answer | |

It's not ok and should not be even considered at all. Public groups and Hierarchical Custom settings are very helpful and would be sufficient.

Sometimes I also create a custom formula field of Boolean type where I have a validation like Field_X__c = 'X' AND $Setup.My_Custom_Seetings__c.Field_Y__c(boolean) and referencing it in validations, report filters, workflows... The advantage of this is when I have to change some common criteria - I just modify this formula.

| improve this answer | |

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.