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
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
As Amrutha said, you can do this validation rule instead of trigger.
If this helps, Please mark it as best answer.
Thanks!!