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
Abhi92Abhi92 

Validation Rule on AccountNumber

I've created a below validation rule on Account, but it's not firing when the length of the Account number is not 8, record getting saved even length is 5 number. What wrong I'm doing ??

AND(
ISBLANK(AccountNumber),
NOT(ISNUMBER(AccountNumber)),
LEN(AccountNumber) <> 8
)
Best Answer chosen by Abhi92
RituSharmaRituSharma
Replace AND with OR.

Your formula should be:

OR(
ISBLANK(AccountNumber),
NOT(ISNUMBER(AccountNumber)),
LEN(AccountNumber) <> 8
)

All Answers

RituSharmaRituSharma
Replace AND with OR.

Your formula should be:

OR(
ISBLANK(AccountNumber),
NOT(ISNUMBER(AccountNumber)),
LEN(AccountNumber) <> 8
)
This was selected as the best answer
AbhishekAbhishek (Salesforce Developers) 
https://developer.salesforce.com/docs/atlas.en-us.usefulValidationRules.meta/usefulValidationRules/fields_useful_validation_formulas_account.htm

Your query is answered in the above official document.

Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.

Thanks.
Abhi92Abhi92

Thanks Ritu, I've already replaced that and it's working. But I'm confused now between AND and OR. 

AND function - Checks whether all arguments are true and return TRUE if all arguments are true, it should fire the validation error if any of the criteria is not satisfying.

OR function - this check whether any of the arguments are true and returns TRUE or FALSE. Returns FALSE only if all arguments are false

Please can you help me out with this.

RituSharmaRituSharma
AND means that all condition should be true and only the validation will fire. Or means that if any of the condition is true then validation will fire.

Please select my answer as the best answer if your problem is resolved. That would help others in future.
Abhi92Abhi92
So in that case for the below condition, it shouldn't fire the validation rule, when I put 12345 as the Account number  is not blank

AND( ISBLANK(AccountNumber),
LEN(AccountNumber) <> 7 )
Abhi92Abhi92
I have taken the above example from Salesforce help document itself
RituSharmaRituSharma
AND( ISBLANK(AccountNumber),
LEN(AccountNumber) <> 7 )

This will throw error if both the conditions are true i.e. account number is blank and length is not blank. But as per your requirement, OR is needed.
RituSharmaRituSharma
Please select my original response as the best answer. That would help others in future.
Julia CarterJulia Carter
Based on the information you provided, it's difficult to determine what might be causing the validation rule to not fire correctly. However, I can offer some suggestions for troubleshooting the issue:
Double-check the syntax of your validation rule to make sure it is correct. You can do this by going to Setup > Object Manager > Account > Validation Rules and clicking on the rule you created. Make sure the formula is correct and there are no errors.
Verify that the validation rule is active. Go to Setup > Object Manager > Account > Validation Rules and make sure the checkbox next to the rule you created is checked.
Check the evaluation criteria for the validation rule. Make sure it is set to "Formula evaluates to true" and that the formula is correct.
Verify that the Account Number field is a required field. If the field is not required, the validation rule may not be triggered when the field is left blank.
Make sure you are testing the validation rule correctly. (https://apksplash.com/) When creating or editing an Account record, enter a value in the Account Number field that is not 8 characters long and try to save the record. If the validation rule is working correctly, you should see an error message preventing the record from being saved.
If you have checked all of the above and the validation rule is still not firing correctly, you may need to contact Salesforce support for further assistance.
jiyaca maryajiyaca marya
excellent information that is quite helpful to me, therefore I appreciate you sharing
Kahoot Login  (https://kahoot-login.info/" target="_blank)