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
HeeseHeese 

Help writing a validation rule

Hi,

I need help writing a validation rule. 

I have an custom account field (picklist) named XYZ.  I would like to create a validation rule for an opporuntity related to the account.
So if an opportunity is created and a picklist value other than N/A is selected it would require the user to type a hyphen into the Opportunity Name. 

I saw this from a list of validation rules.  FIND( " - ", Name ) = 0

Logically it sounds like this.  If ISPICKVAL XYZ_c <> N/A Then require "-"

Thanks in advance
TCAdminTCAdmin
Hello Heese,

You will need to utilize a validation rule similar to the one below.

AND(
  ISPICKVAL(Picklist__c, "XYZ"),
  NOT(CONTAINS(Name, "-"))
)

If the picklist equals the XYZ value and there is not a hyphen in the name field it will error out and not let them save.
Enzo6034Enzo6034
Hello I just need some help on this certain validation rule I created below:
 
AND(
$RecordType.Id = "01270000000DgCU",
IF(ISNULL(CloseDate) = FALSE,
OR(ISNULL(Funnel_Comments__c )), FALSE)
)
 
Based on a recordtypeID, when there is a closed date, the funnel comments box has to have some data in there. Otherwise an error message will appear.
 
I placed the formula, checked the syntax and no errors appear. Although when i test it out on the opportunity, it doesnt work. Can you let me know if there is something wrong with the validation? Thanks 


Message Edited by Enzo6034 on 06-04-2008 10:19 AM
TCAdminTCAdmin
Hello Enzo6034,
 
The close date is a required field on the Opportunity so it should not ever be blank. Also, the ISNULL() function returns a TRUE or a FALSE so there is no reason to compare it to a true or false value.
 
The validation rule below should do what you are looking for. Please let me know if you have issues with it.
 
Code:
AND(
  $RecordType.Id = "01270000000DgCU",
  LEN(Funnel_Comments__c) = 0
)

Enzo6034Enzo6034
Hi Chris,
 
I appreciate the response. Apparently there is a new requirement that I have to change the validation rule. From that validation rule you provided me, how do you base it on certain picklist values from a stage field:
 
Closed Won
Closed Lost
Closed Walk Away
 
Based on those picklist values, sometype of data has to be entered in the comments field. Any response would be helpful.
 
Thanks,
 
Joe
Enzo6034Enzo6034

Is this correct

AND(
$RecordType.Id = "01270000000DgCU",
OR(ISPICKVAL(StageName, "Closed Won"),ISPICKVAL(StageName, "Closed Lost"),ISPICKVAL(StageName, "Closed Walk Away")),LEN(Funnel_Comments__c) = 0
)

TCAdminTCAdmin
Enzo6034,

That looks correct. If you click on the SRC button when posting and placing your code in that dialog box it won't put all of the smilies within it.
Code:
AND(
  OR(
   ISPICKVAL(field1__c, 'value1'),
   ISPICKVAL(field1__c, 'value2')
  )
  LEN(field__c) = 0
)

Enzo6034Enzo6034

Hi Chris,

Thanks for your help. I just have one more question. Do you know a validation rule based on a recordtype where the user can pick only among the 3 picklist values and if they pick something else an error would appear. I am doing this for existing opportunities where the user cant change existing stages but those. I have something I am trying below:

Code:
AND( 
$RecordType.Id = "01250000000DOMu", 
IF(ISNULL(CloseDate) = FALSE, 
OR(ISPICKVAL(StageName, "Closed Won"),ISPICKVAL(StageName, "Closed Lost"),ISPICKVAL(StageName, "Identified")), FALSE))


Thanks,

Joe



Message Edited by Enzo6034 on 06-04-2008 08:01 PM

Message Edited by Enzo6034 on 06-04-2008 08:01 PM
JakesterJakester
Just a quick question, Joe: did you know that you can specify specific picklists for each record type? This can be done completely without coding.
Enzo6034Enzo6034

Hello,

I am aware of that but since this is an existing opportunity, i just want the original picklist but just limit it now to three values. If I change the picklist wouldnt it change the data in the old existing opportunities?

Thanks,

Joe

JakesterJakester
No, changing a picklist only changes the available options - it doesn't modify the existing data.
Enzo6034Enzo6034

Hi,

I got another question. How do I make a lookup field required based on a recordtype using a validation rule?

Thanks,

Joe

TCAdminTCAdmin
Hello Enzo6034,

It will be something like this:
Code:
AND(
  $RecordType.Name = "This Record Type",
  LEN(Lookup__c) = 0
)