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
fullvaluefullvalue 

Maps and Visualforce

Hi I'm wondering if someone can help me.  I just started using Visualforce.  Here is the situation.

I am trying to display opportunity line items with a job number associated to them.  The association is through opportunity.

Opportunity parent of Opportunity Line Items
Opportunity parent of Project

I need to display opportunity line items with a field on the Project.  I have created a map with the data but don't know how to display it in a visualforce page. 

Here is the code to produce the map. 

Code:
private set<ID> opptIds = new set<ID>();
private List<OpportunityLineItem> products = new List<OpportunityLineItem>();
private Map<ID,Project__c> opptproj = new Map<ID,Project__c>();
private Map<String,OpportunityLineItem> jnoli = new Map<String,OpportunityLineItem>();

for (SFDC_Project__c p : [SELECT Opportunity__c from Project__c where Branch__c = :branch]) {
       opptproj.put(p.Opportunity__c,p);
       opptIds.add(p.Opportunity__c);
     }

products = [select Quantity, PricebookEntry.Product2.ProductCode,OpportunityId from OpportunityLineItem where OpportunityId in :opptIds];
 for (Integer i = 0; i <products.size(); i++) {
     jnoli.put(opptproj.get(products[i].OpportunityId).Job_Number__c,products[i]);
 }

Here is the visualforce page.  I got this to work with products but I need to display Job Number so therefore need to do something with the map.

Code:
<apex:repeat value="{!products}" var="product">
{!product.PricebookEntry.Product2.ProductCode}
{!product.Quantity}
<br/>
<br/>
</apex:repeat>

 Maybe there is a better way of doing this.

Any help would be great.  Thanks!

 
fullvaluefullvalue
bump....anyone?
Ron HessRon Hess
you will need to construct a class that has a getter that returns the job number

public class job {
 public string jobnumber { get; set; }
 public product2 product { get; set ; }

// add a constructor...
}

then you can construct a list of these, and you will need a getter for that list as well

public list<job> myJobs { get; set; }

now you can loop thru the myJobs list, and access the product and the job number of each

creating these wrapper classes is very common, they constitute your data model.
fullvaluefullvalue
Thanks Ron.  I came to this thought as well last night and was going to give it a shot today.  Thanks for the head start.