How to display custom error message, when i do not fill the required input fields it will show custom error message.I don't want this standard message(Error: You must enter a value). please give me some ideas


try to use addError method.

Refer to this : https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_sobject.htm

  • Hi, Tejas Kapasi give me one example
    – MMM
    May 5 '15 at 6:36
  • Hi, Simple Example would be like this, code Contact cont = (Contact) stdctrl.getRecord(); if( (String.IsBlank(cont.Email) && (String.IsBlank(cont.phone) ){ cont.email.addError('Please Enter an email Address or Phone Number'); cont.phone.addError('Please Enter a Phone number or Email Address'); }else{ // do something } May 5 '15 at 7:51
  • for (Contact cand : contacts) { if ( (null==cand.Email || cand.Email.length()==0) && (null==cand.Phone || cand.Phone.length()==0) ) { cand.email.addError('Either email or phone must be defined'); cand.phone.addError('Either email or phone must be defined'); } May 5 '15 at 8:02

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