Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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;">
              {!i}
              <apex:outputfield value="{!divisionaddresses[i].Street_Address__c}"/>
              {!divisionaddresses[i].Zip_Code__c}
              {!divisionaddresses[i].State__c} 
              </div>

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
1  
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
add comment

1 Answer 1

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. https://gist.github.com/Oblongmana/2080f5bbf66c74341ae6

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]}"/> 
</apex:repeat>

This will write out everything in your map like this:

Key1:Value1
Key2:Value2
...
KeyN:ValueN

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]}"/> 
</apex:repeat>
share|improve this answer
2  
that was perfect james, thank you so much! –  gfppaste Feb 25 '13 at 22:56
add comment

Your Answer

 
discard

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.