• Ken Kam
  • 0 Points
  • Member since 2015

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
  • 0
We are trying to use the function addError() of sObject instead of ApexPages.AddMessage() in the controller to display error message on the visualforce page right beneath to the inputfield. However when the error is displayed, it shows up on the general section of the tag <apex:pagemessages>, but it does not show up underneath the inputfield. 

Here is a screenshot
User-added image

Here is the test visualforce page with just one field to display for testing. 
<apex:page standardcontroller="Apttus__APTS_Agreement__c" extensions="RequestorALL_VF_Controller" id="page">
    <apex:sectionheader title="test"/>
    <apex:form id="formId">
            <apex:pageblockbuttons id="Buttons">
                <apex:commandbutton value="Save Request" action="{!Save}" />
                <apex:commandbutton value="Cancel" action="{!Cancel}"/>            
            <apex:pageblocksection id="MainInfoSection">
                <apex:inputField value="{!Apttus__APTS_Agreement__c.Name}" required="false"/>

        <apex:outputLabel value="{!Apttus__APTS_Agreement__c.Contracting_Party__r.International_Status__c}" rendered="false" />    
        <apex:outputLabel value="{!Apttus__APTS_Agreement__c.Contracting_Party__r.BillingCountry}" rendered="false" />
        <apex:outputLabel value="{!Apttus__APTS_Agreement__c.Contracting_Party__r.Type}" rendered="false" />
        <apex:outputLabel value="{!Apttus__APTS_Agreement__c.Contracting_Party__r.HCP__c}" rendered="false" />
        <apex:outputLabel value="{!Apttus__APTS_Agreement__c.Contracting_Party_2__r.International_Status__c}" rendered="false" />
        <apex:outputLabel value="{!Apttus__APTS_Agreement__c.Contracting_Party_2__r.BillingCountry}" rendered="false" />
        <apex:outputLabel value="{!Apttus__APTS_Agreement__c.Contracting_Party_2__r.Type}" rendered="false" />
        <apex:outputLabel value="{!Apttus__APTS_Agreement__c.Contracting_Party_2__r.HCP__c}" rendered="false" />

and the snippet of the controller code ...

private boolean showError(SObject sObj, string sName, string errMsg) {
        boolean hasError = false;
        if (sName == null || sName == '') {
            if (errMsg == null) sObj.addError('the value is required');
            else sObj.addError(errMsg);
            hasError = true;
        return hasError;
if (showError(obj, obj.Name, 'Agreement Name is required')) hasError = true;

Any help is appreciated.
  • September 27, 2015
  • Like
  • 0