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
Shuhbam SinhaShuhbam Sinha 

how to remove '. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION,' this text from my UI in lwc

Hello Everyone ,

I need to remove  catch error from my LWC . So basically I have a record edit from and upon submitting i have some validation rules to be checked . So as we know for custom validations Salesforce adds this line  First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION,'  before any validation but my requirement is to show only the validation rule's message not the whole line .
Is there any way to show only validation message . Please help.
Thanks in advance.

Best Answer chosen by Shuhbam Sinha
Shuhbam SinhaShuhbam Sinha

Hello,

I got the exact answer. If anyone wants to refer : -

 

f (error.body.message.includes('FIELD_CUSTOM_VALIDATION_EXCEPTION')) {
                            console.log('FIELD_CUSTOM_VALIDATION_EXCEPTION');
                            this.errorMessage = error.body.message.substring(82+('FIELD_CUSTOM_VALIDATION_EXCEPTION').length);
                            console.log('FIELD_CUSTOM_VALIDATION_EXCEPTIONss',this.errorMessage);
                            this.dispatchEvent(
                                new ShowToastEvent({
                                    title: 'Error updating record',
                                    message: this.errorMessage,
                                    variant: 'error',
                                }),
                            );
                        }

All Answers

Sai PraveenSai Praveen (Salesforce Developers) 
Hi Shuhbam,

Can you check different approaches mentioned on stack exchange.

https://salesforce.stackexchange.com/questions/312612/validation-rule-error-message-not-displaying-in-lwc-updaterecord-toast-event

Let me know if you face any issues.

If this solution helps, Please mark it as best answer.

Thanks,
Shuhbam SinhaShuhbam Sinha

Hello,

I got the exact answer. If anyone wants to refer : -

 

f (error.body.message.includes('FIELD_CUSTOM_VALIDATION_EXCEPTION')) {
                            console.log('FIELD_CUSTOM_VALIDATION_EXCEPTION');
                            this.errorMessage = error.body.message.substring(82+('FIELD_CUSTOM_VALIDATION_EXCEPTION').length);
                            console.log('FIELD_CUSTOM_VALIDATION_EXCEPTIONss',this.errorMessage);
                            this.dispatchEvent(
                                new ShowToastEvent({
                                    title: 'Error updating record',
                                    message: this.errorMessage,
                                    variant: 'error',
                                }),
                            );
                        }
This was selected as the best answer
Manish Chaubey 16Manish Chaubey 16
If you are seeing the error message "First exception on row 0; first error:
FIELD_CUSTOM_VALIDATION_EXCEPTION" in your LWC UI, it means that a custom validation rule has been triggered and it has caused an error.

To remove this error message from your UI, you will need to address the underlying cause of the error. Here are some steps you can follow:
  1. Determine the cause of the error: Look at the error message to determine what caused the custom validation rule to trigger. It may be that some data that was entered is not meeting a specific validation criteria.
  2. Modify the data to meet validation criteria: If the error was caused by incorrect data, modify the data to meet the validation criteria. This could involve making changes to the input or updating data in related records.
  3. Disable the validation rule (temporarily): If you are unable to modify the data to meet the validation criteria, you can temporarily disable the validation rule. However, this should only be done as a last resort, and the rule should be re-enabled once the issue has been resolved.
  4. Test the changes: After making changes to address the underlying cause of the error, test the changes to ensure that the error message no longer appears in the UI.
Note that if the error message is still appearing even after you have addressed the underlying cause of the error, there may be an issue with the custom validation rule itself. In this case, you may need to contact the administrator or developer who created the rule for assistance. If you want to get expert suggestion, you may connect salesforce consulting partners (https://www.streamssolutions.com/partnership/salesforce/) here.