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
Pablo ArgentinaPablo Argentina 

Data validation

hi guys.

Can anybody help me?

I'm trying to validate a field.

 

The idea is the following:

I want to create a field named TEST (TEST__c) that have 2 states. Or it's blank or, if it's not balnk, then, the lenght should be 15

This is a numeric field.

 

This is what i did but it's not working:

OR(NOT(ISBLANK( TEST__c )) , LEN( TEXT( TEST__c ) )  <> 15)

 

Thanks in advance.

 

Best Answer chosen by Admin (Salesforce Developers) 
Ritesh AswaneyRitesh Aswaney

NOT(ISBLANK( TEST__c ) AND LEN( TEXT( TEST__c ) )  <> 15)

 

When you're writing a validation rule formula, you want to write the condition which causes the error message to be returned, so negative thinking !

 

So we have to say return an error if the field is not blank and the length is not 15

All Answers

MJ09MJ09

Use an AND instead of an OR.

 

Your validation rule said, "It is an error if the field is non-blank OR if it's not 15 characters long." Well, if it's 15 characters long, then it's non-blank, so the rule thinks it's an error.

 

Using an AND, the rule says, "It is an error if the field is non-blank AND if it's not 15 characters long." That's what you want.

 

FWIW, when I'm looking at a validation rule, I find it helpful to say "It is an error if..." and then state what the rule says.

 

Good luck!

 

PS. This doesn't really belong in the Apex board -- you'd probably have gotten a quicker response in the General board.

Ritesh AswaneyRitesh Aswaney

NOT(ISBLANK( TEST__c ) AND LEN( TEXT( TEST__c ) )  <> 15)

 

When you're writing a validation rule formula, you want to write the condition which causes the error message to be returned, so negative thinking !

 

So we have to say return an error if the field is not blank and the length is not 15

This was selected as the best answer
Pablo ArgentinaPablo Argentina

I DID IT...... Sorry, you did it.

Thanks a lot!!

 

I've just modified the sentence but now i understand the idea.

 

AND(NOT(ISBLANK( IMEI__c )) ,LEN( TEXT( IMEI__c ) ) <> 15)

 

Thanks for your explanation!