I have an Apex:Repeat at the very top level and inside that depending on the data, I am showing either drop down or checkbox. Now I would like to display apex:pageMessage inside apex:repeat, but since it is inside apex:repeat it is getting displayed multiple times. Is there any way to restrict rendering apex:pageMessage only once inside repeat block? Thanks.

  • You need to use apex:variable to manage the display of page message. Set a counter and increase count in loop and when count is 1, display the message May 18 '17 at 23:54

I haven't styled the components, but this is my take.

You can use apex:variable as suggested by Santanu, I created 2 maps 1 to identify the contact that has error, and the other for putting in custom error message(You can make it one map and check if map's contact does not have a error message too and play with the code as needed)

<apex:page controller="repeatcontorller">
<apex:form >
<apex:pageBlock >
<apex:repeat value="{!Accountlist}" var="acc">
account:{!acc.name} <br/>
    <apex:repeat value="{!acc.contacts}" var="con">
        <apex:pagemessage rendered="{!IF(errormap[con.id],true,false)}" severity="error" summary="{!errormessage[con.id]}"></apex:pagemessage>
        contact: {!con.name}<br/>




public class repeatcontorller {

public list<account> Accountlist{get;set;}
public map<id,boolean> errormap{get;set;}
public map<id,string> errormessage{get;set;}

    public repeatcontorller (){
    errormap = new map<id,boolean>();
    errormessage = new map<id,string>();
        Accountlist =[select id,name,(select id,name from contacts) from account limit 10];
        for(account a:accountlist){
            for(contact c:a.contacts){
                    errormessage.put(c.id,'contact cannot contain name test'+String.valueof(c.id));


enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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