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
Money Care 7Money Care 7 

Error in validation rule

Hi Guys

I have created a validation rule like if one field blank then record would not be saved.its working but error message showing like this

Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Please fill the Value: [].

why this error message coming.i need the only error message Please fill the value.

AND(
       Product_Code__c = "C2",  
   ISBLANK(No_of_ups__c)
)


How it is possible.
Naresh YadavNaresh Yadav
Hi Money

If you are inserting records from standard UI then error message will be "Please fill the Value".
But if you are inserting records using apex code then the error will be like this "Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Please fill the Value: [].".

Mark it as solution if it helps you out.
Thanks
Naresh
Money Care 7Money Care 7
Hi @Naresh Yadav Okay..Could you tell me how to achieve this solution ?
Naresh YadavNaresh Yadav
You can achive this adding custom validation in the apex code like :

IF(someField==null){
      ApexPages.addMessage(new ApexPages.message(ApexPages.severity.error,'Please fill the Value.'));
}

Mark it as solution if it helps you out.
Thanks
Naresh
SalesFORCE_enFORCErSalesFORCE_enFORCEr
You need to catch the exception in your apex code and throw the custom error message something like this
try{
insert obj; //inserting/updating the record, which will fail if the No_of_ups__c is blank so it will go to catch
}
catch(Exception e){
obj.addError('Please fill the value');
}