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
1 Answer
try to use addError method.
Refer to this : https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_sobject.htm
-
-
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 }
Commented May 5, 2015 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'); }
Commented May 5, 2015 at 8:02