2

Set up a validation rule like:

AND(
  ISPICKVAL(PRIORVALUE(StageName), 'Closed Won'),
  ($Profile.Name <> 'System Administrator')
)

After an opportunity is closed won, only system administrators can edit the record. But $profile.name seems to be not working.

Requirement: Once a record is saved as 'Closed Won'. Next time any user whose profile is not system administrator should not be able to edit the record

Thanks.

9

The reason why $Profile.Name <> 'System Administrator' is not working might be due to the default language set at Company level. If it's different than English then all standard profile names are translated. If your organization uses language different than English then there is no longer a profile called 'System Administrator' - it is translated to the language used. This applies also to validation rules, workflows, etc. Is that your case?

In my opinion there are many workarounds but I don't know a perfect solution. I can think of following:

  • hardcoding the Profile Id
  • using clone of System Administrator (custom profile which is not translated)
  • or using a custom label with profile name in correct language (or with translations)
  • perfect.. I think this explanation is more accurate. Thanks neff – sf_user Jun 14 '16 at 10:48
2

You are checking the previous value of the stage instead of the current value.

you need something like

AND(
  ISPICKVAL(StageName, 'Closed Won'),
  ($Profile.Name <> 'System Administrator')
)

but this will prevent anyone other than sys admin to set the stage to closed won. so you might need to include some exceptions by checking if the stage field got changed

AND(
  NOT(ISCHANGED(StageName)),    
  ISPICKVAL(StageName, 'Closed Won'),
  ($Profile.Name <> 'System Administrator')
)

Note : You have to test this for both +ve & -ve scenarios and add other conditions as required.

  • Hi Vamsi, Thanks for your reply. I(System Administrator) am still unable to edit the record after it is set to 'Closed Won'. I tried to use just $Profile.Name <> 'System Administrator' in VR still unable to edit after record is closed won. When I use $Profile.Name = 'System Administrator' I am able to edit the record but even other profiles are also able to edit. – sf_user Oct 17 '15 at 14:35
2

I think you should use

AND( ISPICKVAL(PRIORVALUE(StageName), 'Closed Won'), ($Profile.Name <> 'System Administrator'),  Not(IsNew()))

It will check whether the previous value was closed won and now the user other than system administrator is trying to edit the opportunity. Not just the stage but any other field as well.

Please check that your profile is system administrator while testing.

  • Thanks Manjit for your reply. $profile.name seems to be not working. I checked my profile and I am system administrator. I am trying to edit the record that is already closed won but getting the error mentioned in VR – sf_user Oct 17 '15 at 15:12
  • 1
    Have you tried it with profile Id – manjit5190 Oct 17 '15 at 15:20
  • Manjit, With Profile Id it is working perfectly. But I am trying to avoid hardcoding Ids. – sf_user Oct 17 '15 at 15:27
  • 1
    @pmvsdt I would also recommend you to use profile id as if you change the name of profile you have to change the formula. But if you use profile id you won't ever have to change your validation rule. – MIX DML Oct 17 '15 at 15:32
  • when moving stuff from one sandbox to another, or to production, we have to make sure profile has the same id always. We rarely change profile names. – sf_user Oct 17 '15 at 15:35

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.