I have a custom component to create quote and also have few validation rules been created. Whenever i am trying to create the quote, my validation rules are getting triggered and able to display them on UI, but Expected: i should see only validation message Actual: Im able to see the whole message like this. ValidationError

I am expecting to display only the highlighted error to display on components UI.

Apex class:

                insert qu;          
            }catch(Exception e){            
                throw new AuraHandledException('Error Details : '+e.getMessage());           


if(state == "ERROR"){
                        var errors = a.getError(); 


<aura:if isTrue="{!v.showErrors}">       
        <div class="slds-notify slds-notify_toast slds-theme_error">
            <span class="slds-assistive-text">error</span>
            <div class="slds-notify__content">
                <h5 class="slds-text-heading_small slds-align_absolute-center">Error Message </h5>
                <p class="slds-align_absolute-center">{!v.errorMessage}</p>                

Please help me with the solution


If you catch this exception in DmlException catch block then you will get only validation error message. This exception is caused by a failure in DML operation so it should be catch in DmlException catch block.

Catch DmlException in your code like this.

       insert qu;
    }catch (DmlException ex) {
        throw new AurahandledException('Error Details : ' + ex.getDmlMessage(0));
    } catch (Exception ex) {
        throw new AurahandledException('Error Details : ' + ex.getMessage());
  • Hurray, it worked for me. thanks for your help bilal malik Mar 6 '20 at 7:25
  • Great, Happy to help :) Mar 6 '20 at 7:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.