function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
KSKumaarKSKumaar 

Help needed in Exception class : Required fields are missing: [Account Name]

User-added image

As in the above pic shows, I don't want to display the Standard error message which i rounded in pic. How can i make disable it? I want to display only the message what we used generally in 
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.error,'Error Message'));

I can make this possible by using if - else condition (Please see the code which provided), but i want get it through using try - catch blocks only. And also please tell me that how we are getting Required fields are missing: [Account Name] message. Is that system validation rule or any other error message?
You can also see the code which i have used.
public void comittedResult() {
        try{
        aOne=[select id,name,phone,Industry from Account where ID=:accid];
       /* if (String.isBlank(accName)){
            ApexPages.addMessage(new ApexPages.message(ApexPages.severity.error,'Please enter account name'));
        }//!(accPhone.isNumeric())
        else if(!(pattern.matches('[0-9]+',accPhone))){
            ApexPages.addMessage(new ApexPages.message(ApexPages.severity.error,'Please enter correct phone number'));
        }
        else  {*/
        aOne.name = accName;
        aOne.phone = accPhone;
        update aOne;
        displayPopup = false;
        reflectRecords();
   //   }
     }catch(DMLException e){
         ApexPages.addMessage(new ApexPages.message(ApexPages.severity.error,'Please enter Name'));
     }
     }

Thanks in advance.
KS Kumaar
Rohit K SethiRohit K Sethi
Hi , 

The above message is standard by salesforce. If you don't want this message then  you should use "required=false". 

Try below code to understand this :        
 
//Visual force page
<apex:inputField value="{!acc.name}" required="false"/>
//Apex code
if(String.isNotBlank(acc.name)){
            try{
                insert acc;        
                ApexPages.addMessage(new ApexPages.message(ApexPages.severity.Info,'Record successfully inserted : '+acc.name));
            }catch(Exception e){
                ApexPages.addMessage(new ApexPages.message(ApexPages.severity.error,'Exception is genrated' e.getMessage()));
            }
         }else{
            ApexPages.addMessage(new ApexPages.message(ApexPages.severity.error,'Please enter Name' + e.getMessage()));
         }


Thanks.


Thanks.

 
Rohit K SethiRohit K Sethi
Hi,

There is a bug in above my posted apex code plz use below code :
 
if(String.isNotBlank(acc.name)){
	try{
		insert acc;        
		ApexPages.addMessage(new ApexPages.message(ApexPages.severity.Info,'Record successfully inserted'));
	}catch(Exception e){
		ApexPages.addMessage(new ApexPages.message(ApexPages.severity.error,'Exception is genrated ' + e.getMessage()));
	}
	}else{
	ApexPages.addMessage(new ApexPages.message(ApexPages.severity.error,'Please enter Name'));
}

Thanks.
sunny522sunny522
Hi KS@Room,
       We have one alternate.
Steps
Step 1:In vf page,First use required = false for that required field so that custom error messages will be displayed.
Step 2:Use sample code below to make that field required
 <apex:outputPanel layout="block" style="float: left">
          <apex:outputPanel >
                <div class="requiredInput"><div class="requiredBlock"/>
                      <apex:inputField value="{!acc.name}" required="false" />           
                </div>
          </apex:outputPanel>                               
   </apex:outputPanel>

Go through the example in the link below.Hope it helps you.
http://salesforceglobe4u.blogspot.in/2016/08/how-to-override-standard-required-field.html

Let me know if you need any further help...