1

I have a SObject list that I am iterating through, so my var="standardOppFields"

I created a loop to generate a value for each opportunity. I want to display both the standard fields AND the custom value in the same visual force table. Is this possible?

openOpps = new List<Opportunity>([Select id,Name, Account.Phone,Account.Id,Postal_Code__c,
                                     (Select contact.Name 
                                      From OpportunityContactRoles where role='Primary') 
                                  From Opportunity 
                                  where (ownerId=:UserInfo.getUserId()]);


 Map<String, String> zipToTimeZoneMap = new Map<String, String>();
   for(Opportunity o :openOpps){
     localTime = system.Now().addHours(d).format('hh:mm a');
   }

on my VF page, I'm using this format

<apex:column value="{!openOpps.Postal_Code__c}">
   <apex:facet name="header">  
     <apex:commandLink action="{!openOpps}"> 
       <apex:param value="Postal_Code__c" name="column" ></apex:param>
     </apex:commandLink>
   </apex:facet>
</apex:column> 

When I try to do the same VF format with the localTime variable, it's taking the last value in the loop every time.

5
  • 2
    It sounds possible but we can't help you without more information. Can you post what you have so far and where you are stuck?
    – BarCotter
    Feb 27, 2015 at 15:52
  • 1
    Please post code.
    – Adrian Larson
    Feb 27, 2015 at 15:58
  • @BarCotter I have added the code snippets. Feb 27, 2015 at 16:35
  • What is your question? Are you having problems displaying standard and custom fields? Where is standardOppFields being used in the code? How does localTime come in to this?
    – BarCotter
    Feb 27, 2015 at 16:54
  • 2
    This is a classic wrapper class use case. Basically you need to wrap up the local time value and the Opportunity into a plain Apex class and iterate over that. Lot's of docs on this. Start here: developer.salesforce.com/page/Wrapper_Class
    – pchittum
    Feb 27, 2015 at 16:54

1 Answer 1

0

The reason why you get every time the last value is because you probably have only a single one localTime object or property defined, which you are overwriting again and again in the loop.

Since the page markup is composed after the apex loop has finished, no wonder that all cells in the column end up the same.

We can't tell this for sure, because we miss that part of your code, but it's my guess.

The wrapper pattern metioned by @Peter should solve this by introducing one localTime value per record.

You must log in to answer this question.

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