5

I am trying to display error messages using apex:pageMessages tag but the error block does not show up in the inline visualforce page. Is there any restrictions that a visualforce page should contains only one apex:pageMessages tag? I have two inline vf page that has been embedded in account detail page. I have tried to throw an exception intentionally to see the errors displaying in apex:pagemessages block in my inline vf page. Also the debug log shows VF_PAGE_MESSAGE, please see below. I have also checked the rendered html for the pagemessage html block but did not find anything. Any thoughts please.

Debug Log:

14:56:00.851 (9851921914)|SYSTEM_METHOD_EXIT|[71]|System.debug(ANY)
14:56:00.852 (9852005206)|SYSTEM_METHOD_ENTRY|[73]|ApexPages.addMessage(ApexPages.Message)
14:56:00.852 (9852053414)|VF_PAGE_MESSAGE|Oops, please try again!
14:56:00.852 (9852062966)|SYSTEM_METHOD_EXIT|[73]|ApexPages.addMessage(ApexPages.Message)
14:56:00.852 (9852076604)|SYSTEM_MODE_EXIT|false

Inline Visualforce page that is causing this issue is given below.

<apex:page standardController="Account" extensions="CustomerCreditInfoController" standardStylesheets="true" showHeader="false" sidebar="false">
<link href="/sCSS/30.0/sprites/1401314678000/Theme3/default/base/zen-componentsCompatible.css" rel="stylesheet" type="text/css"/><link href="/sCSS/30.0/sprites/1401314678000/Theme3/default/base/elements.css" rel="stylesheet" type="text/css"/><link href="/sCSS/30.0/sprites/1401314678000/Theme3/default/base/common.css" rel="stylesheet" type="text/css"/><link href="/sCSS/30.0/sprites/1401314678000/Theme3/default/base/rlHovers.css" rel="stylesheet" type="text/css"/><link href="/sCSS/30.0/sprites/1401314678000/Theme3/default/base/chatterCore.css" rel="stylesheet" type="text/css"/><link href="/sCSS/30.0/sprites/1401314678000/Theme3/default/base/chatterExtended.css" rel="stylesheet" type="text/css"/><link href="/sCSS/30.0/sprites/1401314678000/Theme3/default/base/SocialCrm.css" rel="stylesheet" type="text/css"/><link href="/sCSS/30.0/sprites/1401314678000/Theme3/default/base/SocialKeyCRM.css" rel="stylesheet" type="text/css"/><link href="/sCSS/30.0/sprites/1400172052000/Theme3/base/dStandard.css" rel="stylesheet" type="text/css"/><link href="/sCSS/30.0/sprites/1401314678000/Theme3/default/base/extended.css" rel="stylesheet" type="text/css"/>
<c:PageLoadingAnimation />
    <div id="container">
    <apex:pageMessages />
        <apex:form id="cciform">
        <apex:pageBlock >

            <apex:pageBlockSection columns="2">

                <apex:outputText label="Credit Block" value="{!If(CustCreditInfo.creditblock=='','No','Yes') }" id="creditblock"/>          
                <!-- <apex:outputText label="Risk Category" value="{!CustCreditInfo.RiskCategory}" id="riskcategory"/> -->
                <apex:outputText label="Rating" value="{!CustCreditInfo.Rating}" id="rating"/>
                <apex:outputText label="Risk Category" value="{!CustCreditInfo.RiskClass}" id="riskclass"/>

                <apex:outputText label="Credit Limit" id="creditlimit" value="{0,number,currency}">  
                    <apex:param value="{!CustCreditInfo.CreditLimit}" />  
                </apex:outputText>              

                <apex:outputText label="Credit Limit Used" value="{!CustCreditInfo.CreditLimitUsed}" id="creditlimitused"/>
                <!--<apex:outputText label="Country Key" value="{!CustCreditInfo.CountryKey}" id="countrykey"/>-->
                <!--<apex:outputText label="Name" value="{!CustCreditInfo.name1}" id="name"/>-->

                <apex:outputText label="Credit Exposure" id="creditexposure" value="{0,number,currency}">  
                    <apex:param value="{!CustCreditInfo.CreditExposure}" />  
                </apex:outputText>              

               <!--<apex:outputText label="City" value="{!CustCreditInfo.City}" id="city"/>-->
                <!--<apex:outputText label="Region" value="{!CustCreditInfo.Region}" id="region"/> -->
                <apex:outputText label="Currency Key" value="{!CustCreditInfo.CurrencyKey}" id="currencykey"/>

            </apex:pageBlockSection>

            <table width="50%">
                <tr><td>
                <table class="list" cellspacing="0" cellpadding="0" border="0">
                    <tr class="headerRow">
                        <th class=" zen-deemphasize">Aging Periods</th>
                        <th class=" zen-deemphasize">Invoice Count</th>
                        <th class="CurrencyElement zen-deemphasize" scope="col">Amount</th>
                    </tr>

                    <tr class="dataRow even first">
                        <td>0 to 30 Days</td>
                        <td class=" dataCell  ">{!CustCreditInfo.InvLessThan30}</td>
                        <td class=" dataCell  CurrencyElement">
                            <apex:outputText value="{0,number,currency}">  
                                <apex:param value="{!CustCreditInfo.AmtLessThan30}" />  
                            </apex:outputText>              
                        </td>
                    </tr>

                    <tr class="dataRow even">
                        <td>31 to 60 Days</td>
                        <td class=" dataCell  ">{!CustCreditInfo.Inv31To60}</td>
                        <td class=" dataCell  CurrencyElement">
                            <apex:outputText value="{0,number,currency}">  
                                <apex:param value="{!CustCreditInfo.Amt31To60}" />  
                            </apex:outputText>              
                        </td>
                    </tr>

                    <tr class="dataRow odd">
                        <td>61 to 90 Days</td>
                        <td class=" dataCell  ">{!CustCreditInfo.Inv61To90}</td>
                        <td class=" dataCell  CurrencyElement">
                            <apex:outputText value="{0,number,currency}">  
                                <apex:param value="{!CustCreditInfo.Amt61To90}" />  
                            </apex:outputText>              
                        </td>
                    </tr>

                    <tr class="dataRow even">
                        <td>91 to 120 Days</td>
                        <td class=" dataCell  ">{!CustCreditInfo.Inv91To120}</td>
                        <td class=" dataCell  CurrencyElement">
                            <apex:outputText value="{0,number,currency}">  
                                <apex:param value="{!CustCreditInfo.Amt91To120}" />  
                            </apex:outputText>              
                        </td>
                    </tr>

                    <tr class="dataRow odd last">
                        <td>More than 120 Days</td>
                        <td class=" dataCell  ">{!CustCreditInfo.InvGreaterThan121}</td>
                        <td class=" dataCell  CurrencyElement">
                            <apex:outputText value="{0,number,currency}">  
                                <apex:param value="{!CustCreditInfo.AmtGreaterThan121}" />  
                            </apex:outputText>              
                        </td>
                    </tr>

                </table>
                </td>
                </tr>
            </table>
        </apex:pageBlock>
        </apex:form>
        </div>
</apex:page>

Controller:

public with sharing class CustomerCreditInfoController {
    private final Account acct;
    public CustomerCreditInfo cci; 
    public String CustNo {get;set;}
    private List<String> lstReqData {get;set;}

    public CustomerCreditInfoController(ApexPages.StandardController stdController) {
        if(!Test.isRunningTest()) {
            List<String> addl = new List<String> {};
            addl.add('accountnumber');
            stdController.addFields(addl);
        }
        this.acct = (Account)stdController.getRecord();
        System.debug('acct:'+acct);

        if(CustNo == null) {}
    }

    public CustomerCreditInfo getCustCreditInfo() {
        try {
            DMsapComDocumentSapSoapFunctionsMcS.Z_GSSMWFM_HNDL_EVNTRQST00_Binding sap1 = new DMsapComDocumentSapSoapFunctionsMcS.Z_GSSMWFM_HNDL_EVNTRQST00_Binding();       
            Map<String,String> mapSAP = new Map<String,String> {};
            DMsapComDocumentSapSoapFunctionsMcS.ZgssmbstDatarcrd01 req = new DMsapComDocumentSapSoapFunctionsMcS.ZgssmbstDatarcrd01();      
            lstReqData = new List<String> {};
            //populating item values

            String EventType = 'EVENT[.]SFDC-CUSTOMER-CREDIT-INFO-GET[.]VERSION[.]0[.]RESPONSE-TYPE[.]FULL-SETS';
            String InputFields = '';
            String InputData = 'ZGSEST_CSTMRSRCH01[.]'+CustNo;
            lstReqData.add(EventType);
            lstReqData.add(InputFields);
            lstReqData.add(InputData);
            req.item = Utility.LoadRequestData(lstReqData);
            sap1.timeout_x = 90000;
            ProcessorControl.inGetCreditInfo = true;
            DMsapComDocumentSapSoapFunctionsMcS.ZGssmwfmHndlEvntrqst00Response_element ret =  sap1.ZGssmwfmHndlEvntrqst00('',req);
            System.debug('Bapiret'+ret.DpostMssg.item);
            mapSAP = Utility.ParseResponse(ret);

            cci = new CustomerCreditInfo(); 
            if(!mapSAP.isEmpty() && mapSAP.size()>0) {
                    cci.CreditBlock = mapSAP.get('CRBLB');
                    cci.RiskCategory = mapSAP.get('CTLPC');
                    cci.RiskClass = mapSAP.get('CTLPC_TEXT');
                    cci.Rating = mapSAP.get('DBRTG');
                    cci.CreditLimit = Decimal.valueOf(Utility.getFixedMinusSymbol(mapSAP.get('KLIMK')));
                    String st = mapSAP.get('KLPRZ');    
                    cci.CreditLimitUsed = st.substring(0, st.length())+'%';
                    //cci.SAP_KUNNR__c = mapSAP.get('KUNNR');
                    cci.CountryKey = mapSAP.get('LAND1');
                    cci.Name1 = mapSAP.get('NAME1');
                    st = mapSAP.get('OBLIG');
                    cci.CreditExposure = Decimal.valueOf(Utility.getFixedMinusSymbol(st.substring(0, st.length())));
                    cci.City = mapSAP.get('ORT01');
                    cci.Region = mapSAP.get('REGIO');
                    cci.CurrencyKey = mapSAP.get('WAERS');
                    cci.AmtLessThan30 = Decimal.valueOf(mapSAP.get('B1_AMT'));
                    cci.InvLessThan30 = mapSAP.get('B1_COUNT');
                    cci.Amt31To60 = Decimal.valueOf(mapSAP.get('B2_AMT'));
                    cci.Inv31to60 = mapSAP.get('B2_COUNT');
                    cci.Amt61To90 = Decimal.valueOf(mapSAP.get('B3_AMT'));
                    cci.Inv61To90 = mapSAP.get('B3_COUNT');
                    cci.Amt91To120 = Decimal.valueOf(mapSAP.get('B4_AMT'));
                    cci.Inv91To120 = mapSAP.get('B4_COUNT');
                    cci.AmtGreaterThan121 = Decimal.valueOf(mapSAP.get('B5_AMT'));
                    cci.InvGreaterThan121 = mapSAP.get('B5_COUNT');
            } else {
                throw new CustomException('Custom Exception thrown');
            }
        }catch (Exception e) {
            System.debug('Customer Credit Info Exception:'+e);
            ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.FATAL,'Oops, please try again!');
            ApexPages.addMessage(myMsg);
        }
        return cci;
    }


/*
Wrapper for Customer Credit Info

Credit Block    
 Country Key    
Risk category   
Name    
Risk Class  
Credit exposure 
Rating  
City    
Credit Limit    
Region  
Credit limit used   
Currency Key

*/    
    public class CustomerCreditInfo {
        public String CreditBlock{get; set;} //MONTH_1
        public String CountryKey{get; set;} //UMNETWR_CUR
        public String RiskCategory{get; set;} //UMNETWR
        public String Name1 {get;set;} //UMWAVWR_CUR
        public String RiskClass{get; set;} //UMWAVWR    
        public Decimal CreditExposure{get; set;} //UMKZWI1_CUR
        public String Rating{get;set;} //UMKZWI1
        public String City{get; set;} //MONTH_1
        public Decimal CreditLimit{get; set;} //UMNETWR_CUR
        public String Region{get; set;} //UMNETWR
        public String CreditLimitUsed{get;set;} //UMWAVWR_CUR
        public String CurrencyKey{get; set;} //UMWAVWR    
        public Decimal AmtLessThan30{get; set;} //B1_AMT
        public String InvLessThan30{get; set;} //B1_COUNT
        public Decimal Amt31To60{get; set;} //B2_AMT
        public String Inv31to60{get; set;} //B2_COUNT
        public Decimal Amt61To90{get; set;} //B3_AMT
        public String Inv61To90{get; set;} //B3_COUNT
        public Decimal Amt91To120{get; set;} //B4_AMT
        public String Inv91To120{get; set;} //B5_COUNT
        public Decimal AmtGreaterThan121{get;set;} //B5_AMT
        public String InvGreaterThan121{get;set;} //B5_COUNT
    }

}
2
  • baskaran - as you are a regular poster, it would be kind if you marked Bob Buzzard's answer as the Solution
    – cropredy
    Sep 17, 2014 at 23:29
  • @crop1645 done as per your suggestion.
    – Bforce
    Sep 18, 2014 at 4:38

3 Answers 3

4

I suspect the issue here is that the apex:pageMessages tag has been evaluated before your getter is called, so even though you are adding the message correctly to the collection, the rendering engine doesn't take it into account as it has already processed the tag.

As the getter can be called multiple times, it doesn't feel like the best place to be adding a message as you could end up with a long list of duplicates. Looking at the code you are also likely to be making a number of web service callouts. A better way to do this would be to carry out the web service callout from the constructor and setup the cci record there, that way you know it will only happen once and the message will be added before the apex:pagemessages tag is evaluated.

2
  • Thanks @Bob Buzzard. As per your suggestion, I have changed the code and removed the get method and placed all the webservice code inside of the controller itself. But again the issue persisted. And after that i just take the apex:pagemessages and placed it above apex:pageBlock and it renders properly. Thanks for your guidance.
    – Bforce
    Jun 18, 2014 at 15:56
  • As long as you got there. Jun 18, 2014 at 16:25
1

You essentially have to do 1 of 2 things in order to get the errors to show up.

1) Get the messages to be thrown somewhere from constructor execution.

2) Rerender the messages after an error has been thrown.

Note: I also noticed that your getCustCreditInfo is likely firing several times. I believe each get call makes it fire again.

9
  • Thanks @dphil. I have updated my question with the debug log lines. Please have a look. Also i have checked debug log thoroughly that the getcustcreditinfo method called only one time. There is no issue with apex:pagemessages in my another inline vf page which is also embedded in the same account detail page.
    – Bforce
    Jun 16, 2014 at 19:05
  • The Note I made doesn't really effect your problem. I was just noting it for a potential side effect. On your other VF page, is your message being rerendered somehow? That would explain why it would work and this one doesn't.
    – dphil
    Jun 16, 2014 at 19:14
  • Yes, @dphil. I checked the vf page where apex:pagemessages has been working. But this one is really taking my time. But i think it should be a very silly mistake from my side unfortunately i cannot find it out.
    – Bforce
    Jun 16, 2014 at 19:19
  • 1
    The other guy pointed out something that might be helpful. Try using an apex:outputPanel instead of that div tag.
    – dphil
    Jun 16, 2014 at 20:05
  • Thanks @dphil. I have changed the code and made apex:pagemessages inside of apex:outputpanel, but still it is not working no error is displaying on the top of the inline vf page. Any thoughts?
    – Bforce
    Jun 17, 2014 at 9:31
0

I too display warnings and confirmations via ApexPages.addmessage()

ApexPages.addmessage(new ApexPages.message(ApexPages.severity.CONFIRM,msg));

I remember having some problems with that before I put my pagemessages tag inside an outputpanel tag (see below)

<apex:page standardController="LogEntry__c"  extensions="LogEntryController">
 <apex:sectionHeader title="Manage " /> 
    <apex:form >    
            <apex:outputPanel id="pnlMessages" >
                <apex:pagemessages ></apex:pagemessages>
            </apex:outputPanel>
        ...

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .