0

I have a VF page & controller that is querying accounts and putting them into a list, and them displaying the fields Account Name, State,and Last Activity.

I have a custom setting that is a list of zip codes (which is also a field on account) and their corresponding avg per capita income.

I am able to get values from custom settings, but have trouble understanding iterating them to match the account data displayed.

Is using a map the best way to accomplish this?

2 Answers 2

1

Since both your account list and your custom settings list have the zip codes you could use that as the key in a map. Query your custom settings and put them in a map similar to this example.

Map<String, Double> zipToCapitaMap = new Map<String, Double>(); //Assuming field types

for(Account a :myListOfAccounts){
    Double avgPerCapita = zipToCapitaMap.get(a.zipcode);
    String myAccountInfo = 'Name '+a.Name+' State '+a.State+' AvgPerCapita '+ avgPerCapita; 
}

Double check that your zip codes in the custom settings are exactly as they are on the accounts. No extra white space or quotes.

1
  • marking as the best answer as my custom setting is of the List variety Commented Feb 26, 2015 at 15:14
0

Another way is to access the custom setting on the page directly and use one of the Salesforce Functions for compare for example:

<apex:repeat value="{!accounts}" var="a">
    <apex:outputText value="{!a.name}" 
                     rendered="{!CONTAINS(!$Setup.SettingsObject__c.SETTING__c, a.PostalCode})}" />
</apex:repeat>

Used $Setup global variable here:

A global merge field type to use when referencing a custom setting of type “hierarchy.”

You must log in to answer this question.

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