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
NYCMeghanNYCMeghan 

Validation Rule to Prevent Opportunity Creation

I have two profiles for our sales users - a "Senior Account Executive" that needs (and has) r/w access to all opportunities.  The users assigned to the other profile, "Account Executive"  need to be able to see all accounts, but should not create opportunities on accounts they do not own.  The only way I can think to prevent this is to put in a validation rule to check account ownership and error on any attempts to create the opp.  Every attempt I have made at this gives me a syntax error.  I know this should be a very basic rule - but I can't seem to get it to work.

Any suggestions?
SubMensaSubMensa
You can try the following within your Opportunity Validation Rule:

AND (
  ISNEW() ,
  Account.OwnerId <> $User.Id ,
  $Profile.Name = "Account Executive"
)
dcwdcw

Thanks for your post, it helped me in a similar situation.  Your solution however allows me to enter the "invalid" data, then prevents me when I save.

Is there a way to prevent me from hitting the New button (hiding it?) or displaying an error message immediately after hitting the New button?

KC-CRM AnalystKC-CRM Analyst
dcw,
 
Could you please clarify the situation you are trying to prevent?
 
Buttons can be hidden in Enterprise Edition and higher through the use of profile controls but, I think your situation may be different than how I am conceptualizing it.
dcwdcw

We have two custom objects... Samples and Sample Lines.  Samples is a order header where we capture information like the address and shipping information.  Sample LInes is one line for each product being sent.

The Sample page layout has a button for "New Sample Line" and fields for "Date Sent" and "Tracking Number".  I want to prevent use of the "New Sample Line" button when the "Date Sent" and "Tracking Number" fields are not null.  In other words, lines can only be entered until the Sample has been sent.

The validation rule solution you provided prevents the completion of the insert of the new Sample Line, but only after the "New Sample Line" button has been pressed and the data has been entered.  I'm trying to stop the failed attempt earlier in the process.

KC-CRM AnalystKC-CRM Analyst

I think you may have to do some of the validation rule as part of the custom button programming. 

I'll look into it and get back to you.