function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Mubarak Hussain 1Mubarak Hussain 1 

Validation rule in Opportunity button

Hi all,
How to write a validation rule for button in Opportunity.
For ex:am having close opportunity button in Opportunity.Now i want only dealer user need to close the opportunity.if any one try to close it need to throw error.
I used apex class but am not getting.


Thanks
Gyanender SinghGyanender Singh
Hi Mubarak,

As per your requirement you have a custom button on oppportunity name is Close Opportunity and you want that if some user want to close the opportunity then they can do and for remaing you want to get some error message . so  write the javascript on your custom button like this:
 
var useraliasname = '{!$User.Alias}'; 
if (useraliasname != "abc" || useraliasname != "xyz") 
{ 
alert('You do not have sufficient privilages') 
}

in this javascript use the alias name of the user for that you want to get the error message.

Thanks
Gynai
Vishal Negandhi 16Vishal Negandhi 16
Hi Mubarak, 

Other option for you is to simply have a validation rule. 

Example:
AND(ISCHANGED(StageName), OR(ISPICKVAL(StageName, 'Closed Won'), ISPICKVAL(StageName, 'Closed Lost')), $Profile.Name != 'NAME_OF_DEALER_USER_PROFILE')