I am trying to upsert a record and and I am expecting, when I hit the button, then it will check for Invalid Email address, and if there is any then it will show me the error in the pageMessage.


try {
  upsert accctObj;
} catch(DMLException ex) {
   ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'Random Message')); 


I checked in the debug log what ex.getMessage() is showing.

 INVALID_EMAIL_ADDRESS, User Email: invalid email address: sd: [User_Email__c]

But, I am not able to see above message, instead it's coming,

User Email:User Email: invalid email address: sd

I want it should come

User Email: invalid email address: sd
  • You need to get the error message like you said ex.getMessage() in the catch block and display it. Feb 5 '15 at 8:35
  • @MihaiNeagoe : Fun fact, I did and put it in ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'Random Message')); return; But still Prvious Error message is coming.
    – SFDC Geek
    Feb 5 '15 at 8:37
  • @SFDCGeek: Did you try ex.getDMLMessage[0]? Feb 5 '15 at 8:44
  • @Vignesh : Yeah, tried, same error. Thing is It is doesn't care about what you give in Catch block, It only shows Error message User Email:User Email: invalid email address: sd
    – SFDC Geek
    Feb 5 '15 at 8:54
  • Have you written "return null;" after ApexPages.addMessage() ?
    – snehakem
    Feb 5 '15 at 9:57

Your Answer

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

Browse other questions tagged or ask your own question.