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
Hank BurtonHank Burton 

Hello All,I want to write trigger to validate account number should be 7 digit. So, please can anyone help me.

Salesforce TechieSalesforce Techie
write a validation rule instead
Example: Validates that the Account Number is exactly seven digits (if it is not blank)
Validation Rule on Account:
AND(
   ISBLANK(AccountNumber),
   LEN(AccountNumber) <> 7
)

Error Message : Account Number must be seven digits.
Error Location: Account Number
AnkaiahAnkaiah (Salesforce Developers) 
Hi Hank,

As Amrutha said, you  can do this validation rule instead of trigger.
AND(
   NOT(ISBLANK(AccountNumber)),
   LEN(AccountNumber) <> 7
)

If this helps, Please mark it as best answer.

Thanks!!