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
Christian Dylan CarterChristian Dylan Carter 

Nested <apex:repeat> within an <apex:map>

I'm running into some odd errors with a nested apex:repeat inside of an apex:map (on API 34.0). My code looks like this:
<apex:map width="500px" height="500px" center="53704">
        <apex:repeat value="{!matches}" var="match">
            <apex:mapMarker title="{!match.Provider__r.Name}"
             position="{latitude:{!match.Provider__r.Latitude_Display__c},longitude:{!match.Provider__r.Longitude_Display__c}}">
                <apex:mapInfoWindow>
                    <apex:repeat value="{!$ObjectType.Account.FieldSets.Provider_Detail_Pin}" var="f">
                        <apex:outputPanel layout="block" style="font-weight: bold;">
                            <apex:outputField value="{! match.Provider__r[f] }"/>
                        </apex:outputPanel>
                    </apex:repeat>
                </apex:mapInfoWindow>
             </apex:mapMarker>
        </apex:repeat>
    </apex:map>

This results in an odd error:
Result: [COMPILE FAILED]: (ReferralMap) <apex:outputPanel> cannot be used inside <apex:map> in the markup (Line: 1, Column: -1)

If I remove the outputPanel I get a message saying that outputField is not acceptable. If I remove that and just use an expression, that also fails.

As soon as I remove the second apex:repeat and hard code fields instead of a FieldSet, the errors go away and I can have an outputPanel in the map. That said, I'd much rather have a FieldSet!

Any ideas?

Later on in the page, I use this pattern very successfully, it only fails inside the <apex:map>:
<apex:repeat value="{!providersMatchingSome}" var="match"> 
        <apex:pageBlockSection title="{!match.Provider__r.Name}">
            <apex:repeat value="{!$ObjectType.Account.FieldSets.Provider_Detail_Block}" var="f">
                <apex:outputField value="{!match.Provider__r[f]}" /><br/>
        </apex:repeat>
        </apex:pageBlockSection>
    </apex:repeat>

 
hitesh90hitesh90
Hello Carter,

Can you please post your full Controller code here?

Thank You,
Hitesh Patel
Email :- hiteshpatel.aspl@gmail.com
Mo. +91 7843045098
http://mrjavascript.blogspot.in/
Christian Dylan CarterChristian Dylan Carter
Hi Hitesh,

I am using a small controller extension to filter a relationship, but I have just tested and confirmed that the issue comes up even with just the standard controller and no additional apex.

Thanks,
hitesh90hitesh90
Okay Carter,

Please find below sample code for your map requirement.

Visualforce Page:
<apex:page controller="mapPageExtension">
    <apex:map width="500px" height="500px" center="53704">
        <apex:repeat value="{!matches}" var="match">
            <apex:mapMarker title="{!match.Provider__r.Name}"
             position="{latitude:{!match.Provider__r.Latitude_Display__c},longitude:{!match.Provider__r.Longitude_Display__c}}">
                <apex:mapInfoWindow>
                    <apex:outputPanel layout="block" style="font-weight: bold;">
                        <apex:outputText escape="false" value="{!mapProviderDetailPin[match.id]}"/>
                    </apex:outputPanel>
                </apex:mapInfoWindow>
             </apex:mapMarker>
        </apex:repeat>
    </apex:map>
</apex:page>

Apex Class:
public class mapPageExtension{
    public List<Account> matches{get; set;}
    public map<Id, String> mapProviderDetailPin {get; set;}
    public mapPageExtension(){
        mapProviderDetailPin = new map<Id, String>();
        string strSOQL = 'SELECT ID, Provider__r.Name ';
        for(Schema.FieldSetMember f : this.getFields()) {
            strSOQL += ', ' + f.getFieldPath();
        }
        strSOQL += ' FROM Account LIMIT 10';
        matches = database.query(strSOQL);
        for(Account acc: matches){
            string strProviderDetailPin = '';
            for(Schema.FieldSetMember f : this.getFields()) {
                if(acc.get(f.getFieldPath()) != null){
                    strProviderDetailPin += acc.get(f.getFieldPath()) + '<br/>';
                }             
            }    
            mapProviderDetailPin.Put(acc.id, strProviderDetailPin);        
        }
    }    
    public List<Schema.FieldSetMember> getFields() {
        return SObjectType.Account.FieldSets.Provider_Detail_Pin.getFields();
    }
}

Thank You,
Hitesh Patel
Email :- hiteshpatel.aspl@gmail.com
http://mrjavascript.blogspot.in/
Christian Dylan CarterChristian Dylan Carter
HI Hitesh,

Taht works! Thanks. Do you know why there's an error in nested repats within a map? Is this a platform bug, or a limit?
hitesh90hitesh90

Yes Carter,

This is the syntax of using "<apex:mapInfoWindow>" tag in visualforce page. this is not a limitation or bug. we can't user <apex:repeat> inside this tag.

Thank You,
Hitesh Patel
Email :- hiteshpatel.aspl@gmail.com
http://mrjavascript.blogspot.in/