Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So, given the following controller snippet and VF page snippet...

public Map<String, Region__c> divisionaddresses {get; set;}
public List<String> allDivisions {get; set;}

public filladdresses()
    Region__c temp = new Region__c();

    for(String div: allDivisions)
        temp = [SELECT ID, name, Zip_Code__c, Street_Address__c, State__c FROM Region__c][0];
        divisionaddresses.put(div, temp);

<apex:pageBlock mode="edit" id="results">
<apex:repeat value="{!allDivisions}" var="i">
<div id="head" style ="height: 20px; background-color:#66CCFF;width:100%;text-align:center; font-size:15px; font-weight:bold;">
              <apex:outputfield value="{!divisionaddresses[i].Street_Address__c}"/>

Why wouldn't the name, zip code, and streetaddress be rendering in the visualforce page. (allDivisions does in fact have values in it, so that's not it). Is there another way to dereference these objects?

share|improve this question
so for all division do u want to dill in the same street address !!!! Whats the whole point of using a query? – Rao Feb 21 '13 at 21:12
up vote 4 down vote accepted

Edit: May have misunderstood the question a little! Your query seems a bit off:

temp = [SELECT ID, name, Zip_Code__c, Street_Address__c, State__c FROM Region__c][0];

This is getting the same Region__c entry in every single query, which may be the start of the problem.

This particular Region__c may not have its fields populated -which could be why your values don't appear to render. Maybe chuck a System.debug(temp) after that line and make sure there's some content

Also: as a general rule - SOQL queries in a loop is a no-no if you can avoid it, as you can hit the SOQL limit pretty fast depending on the number of iterations!

I've got some boilerplate code that will do what you're after in terms of map reference here.

I'm sure you know what you're doing map-wise, so here's the VF bit from that gist

<apex:repeat value="{!divisionaddresses}" var="key">  
    <apex:outputText value="{!key}:"/>
    <apex:outputText value="{!divisionaddresses[key]}"/> 

This will write out everything in your map like this:


Suppose that you want to you use your "allDivisions" List as your key for lookups (maybe you've got that list in a particular order and that's how you want it on the page, or perhaps it's got a subset of the divisions that you want instead of every single division that's in the map). You can then do this instead:

<apex:repeat value="{!allDivisions}" var="division">  
    <apex:outputText value="{!division}:"/>
    <apex:outputText value="{!divisionaddresses[division]}"/> 
share|improve this answer
that was perfect james, thank you so much! – gfppaste Feb 25 '13 at 22:56

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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