NOT(ISNUMBER(AccountNumber)) - Which means only Numeric can be entered because datatype of AccountNumber is Text. ISBLANK( AccountNumber )---If the Account number field is blank
This will throw error or trigger validation rule when AccountNumber is Text and If the Account number field is blank .
thank you akshay.. and small doubt i have requirement if i leave a field as blank and save it so that i need a message as no field enter and at the same time if i enter alpha numeric number i need a message as its not alphanumeric..can we do it in one validatation
Your problem has solved through trigger. 1-If your Account number is empty then account created. 2-If you enter Account Number is string then Account not create and through error. 3-If you update Account Number and try to insert string then through error.
trigger AccountNumberMustIntegerType on Account (before insert,before update) { for(Account ac:Trigger.New){ if(ac.AccountNumber!=Null){ if(ac.AccountNumber.isNumeric()){ ac.AccountNumber=ac.AccountNumber; } else{ ac.AccountNumber.addError('Field must be integer type'); } } } }
Please let me know if you have any query.
Please mark it as best Answer if you find it helpful.
//Helper Class
public class AccountNotEmpty {
public static void isAccount(List<Account> accList){
for(Account ac: accList){
if(ac.AccountNumber == Null){
ac.AccountNumber.addError('Field is not be Empty');
}
else if(ac.AccountNumber.isNumeric()){
ac.AccountNumber=ac.AccountNumber;
}
else{
ac.AccountNumber.addError('Field must be integer type');
}
}
}
}
//Tregger Class
trigger AccountNumberNotEmpty on Account (before insert,before update) {
if(trigger.isBefore){
AccountNotEmpty.isAccount(trigger.new);
}
}
Try with OR instead of AND , this will ensure that both conditions are checked. I tried for SSN field, it works. OR( ISBLANK( SSN__c ), NOT(ISNUMBER( SSN__c )) )
ISBLANK( AccountNumber )---If the Account number field is blank
This will throw error or trigger validation rule when AccountNumber is Text and If the Account number field is blank .
Please try this:
AND(
ISBLANK(AccountNumber),
NOT(ISNUMBER(AccountNumber))
)
Thanks
Akshay
after i applied this code i jst checked by entering some random alpha numeric like xyz12 it saves and not giving any error.why
By default the Account Name field is Mandatory and you cannot left is as a blank.
Thanks
Developer Forum
NOT(ISNUMBER(AccountNumber))
Thanks
Akshay
Sra,
No, It's not possible, if you want to display more than one errors then you can use more than one validation rules.
The problem will be solved.
can we slove it by using triggers
Your problem has solved through trigger.
1-If your Account number is empty then account created.
2-If you enter Account Number is string then Account not create and through error.
3-If you update Account Number and try to insert string then through error.
trigger AccountNumberMustIntegerType on Account (before insert,before update) {
for(Account ac:Trigger.New){
if(ac.AccountNumber!=Null){
if(ac.AccountNumber.isNumeric()){
ac.AccountNumber=ac.AccountNumber;
}
else{
ac.AccountNumber.addError('Field must be integer type');
}
}
}
}
Please let me know if you have any query.
Please mark it as best Answer if you find it helpful.
Thank You
Ajay Dubedi
Yes, we can please try the below code:
Thanks
Akshay
ISBLANK( account_number__c ),
NOT( ISNUMBER( account_number__c))
)
IT SHOULD NOT BE NUMERTIC AND IT SHOULD NOT BE IT WORKS TRY THIS
OR(
ISBLANK( SSN__c ),
NOT(ISNUMBER( SSN__c ))
)