I need to write a trigger on a Enhanced Notes ( which are stored as ContentNote records ). I need to match a certain text in the note body and then show the custom exception on the note component itself ( which is a standard component and does not show up in the Classic ).
Requirement: Show custom error message
Tried so far: addError()
, AuraHandledException
, custom built in exceptions
Issue: The only error message that the component shows is the generic one that goes like 'Unable to insert record. Please contact your salesforce admin.'
I have tried the above but it never shows the error messages that I put up. I believe this is because the lightning component also needs to be having the code that handles the exception cases which it is doing, but it is only showing the standard error message that it is bound to show.
This is what I have tried: P.S. I have removed the irrelevant code
public class ContentVersionTriggerHandler {
public static void beforeInsertUpdate( List<ContentVersion> newList ) {
for( ContentVersion cv : newList ) {
if( CRITERIA_MATCHED ) {
throw new AuraHandledException( 'Error occurred' );
}
//used this without try catch - throws the error but not this custom message
/*if( match.find() ) {
cv.addError( 'Error occurred' );
}*/
}
}
}