+ Start a Discussion
neckrneckr 

Help Binding a Map<ID, List<Custom_Obeject__c>> to Inputfield in VF

I am trying to figure out the VF syntax to display the input fields of my map.

 

For every Con_Service_Task_Request__c there are 3
Customer_Reference_Report__c and associated CustomerReferenceContact records.

 

I want to render each desired Con_Service_Task_Request__c record inputfield in a pageblock section with its 3 associated

Customer_Reference_Report__c inputfields.

 

I tried a few things based on examples from available resources but no luck, and not sure where to go next. Here is my page and controller, any direction is much appreciated.

 

 

<apex:repeat value="{!ST}" var="STasks" >  
<apex:pageBlockSection columns="3"  title="Service Task Verification Details: {!STasks.Service_Code__c}" collapsible="true" id="STList" >                    

<apex:inputField value="{!STasks.Associated_License__c}" rendered="{!STasks.LV_Required_Code__c==0}"/>
<apex:inputField value="{!STasks.Associated_Insurance_Policy__c}" rendered="{!STasks.GLIV_Required_Code__c==0}"/>
<apex:inputField value="{!STasks.Associated_Eco_Accreditation__c}" rendered="{!STasks.EFAV_Required_Code__c==0}"/>


<!--<apex:repeat value="{!mapST_Cusrefs[STasks.ID]}" var="CRV" >
 
<apex:inputField value="{!mapST_Cusrefs[CRV].CRV_Contact__r.LastName}" />-->

                 
<!--</apex:repeat>--> <!-- This was the most logical approach but tells me Map Key not found -->


<apex:inputField value="{!mapST_Cusrefs[STasks.ID][0].CRV_Contact__r.LastName}" /> <!--This works, but only gives me one Contact record -->

<apex:inputField value="{!mapST_Cusrefs[STasks.ID][1].CRV_Contact__r.LastName}" /> <!--Error: Subscript value 1 not valid. Must be between 0 and 0 -->


<apex:inputField value="{!mapST_Cusrefs[STasks.ID][2].CRV_Contact__r.LastName}" /> <!--Error: Subscript value 1 not valid. Must be between 0 and 0 -->

                            
</apex:pageBlockSection>                        
 </apex:repeat>

 

 

 

 

 

 

            public Map<ID, List<Customer_Reference_Report__c >> mapST_Cusrefs
{
    get
    {
       if(mapST_Cusrefs == null)
       {
mapST_Cusrefs= new Map<ID, List<Customer_Reference_Report__c >>();   
       }
       return mapST_Cusrefs;
    }
   set;
}
               
     public List<Con_Service_Task_Request__c> getST()     
       {        
         if ( (null!=getAccount().id) && (ST == null) )
              
       {            
        ST=[SELECT Id, Account__c, Service_Code__c, Associated_Eco_Accreditation__c,Associated_Insurance_Policy__c, Associated_License__c, LV_Required_Code__c, GLIV_Required_Code__c, EFAV_Required_Code__c                          
        FROM Con_Service_Task_Request__c                           
        WHERE Account__c = : getAccount().ID                          
        ORDER BY Service_Code__c];
          }
        
        for(Con_Service_Task_Request__c STasks : ST){
        
        cusrefs = [SELECT Id, CRV_Account__c, CRV_Contact__r.ID, CRV_Contact__r.Company_Name__c, CRV_Contact__r.Email, CRV_Contact__r.Phone, CRV_Contact__r.LastName,CRV_Contact__r.FirstName, CRV_Service_Performed__c, CRV_Service_Date__c, CRV_Service__r.Service__r.For_Business__c                           
        FROM Customer_Reference_Report__c                           
        WHERE CRV_Service__c = : STasks.ID                         
        ORDER BY CRV_Service_Performed__c];
        
        
        CustomerReferenceContact = new List<Contact>(); 
            for (Customer_Reference_Report__c CRV : cusrefs) {
                CustomerReferenceContact.add(CRV.CRV_Contact__r );
                } 
        
        if(cusrefs==null){
        mapST_Cusrefs.put(STasks.ID, new List<Customer_Reference_Report__c>());
        }
                   mapST_Cusrefs.put(STasks.ID, cusrefs);
                   
              }
                                                       
        return ST;  
        
         }
           

 

 

 

aballardaballard

Well, from the definmitions, it would look like 

<apex:repeat value="{!mapST_Cusrefs[STasks.ID]}" var="CRV" >

iterates over a list selected from the map.  So CRV refers to successive customer_reference_reports.    

 

So I'd expect the inputField inside the repeat to be something like

 

<apex:inputField value="{!CRV.CRV_Contact__r.LastName}" />

Certainly not a what you have which seems to be trying to use the value as CRV as a key in the map.