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
Mathew Andresen 5Mathew Andresen 5 

Dynamic binding of mapping

Hi,

I'm trying to use dymamic binding of maps to loop through a map and thus my page blocks.  But I'm getting a wierd error 

"Value 'core.apexpages.el.adapters.RuntimeTypeMetadataELAdapter@6149c49c' cannot be converted from core.apexpages.el.adapters.RuntimeTypeMetadataELAdapter to com.force.swag.soap.DateOnlyWrapper."

The looping part of the visualforce
<apex:repeat value="{!opp90Map}" var="category" >     
        <td width="25%" valign="top">
    	<apex:pageBlock title="Top 90 Opp for {!category}">
     <apex:pageBlockTable value="{!opp90Map[category]}" var="opp">

and the map 
public Map<String, List<OppWrapper>> opp90Map {get; set; }  
        repNameList = new List<String>{'Brit', 'Emma', 'Jeanette', 'Kara'};
        opp90Map = new Map<String, List<oppWrapper>>();

the whole thing is a bit too big, but I include for completion sake

Thanks,
public class GoalsOverView_Class {
    
    List<Opportunity> oppListStart;
    List<OppWrapper> opp90RepList;
    public List<OppWrapper> opp90AllList  { get; set; }
	public List<OppWrapper> opp90BritList  { get; set; }
    public List<OppWrapper> opp90EmmaList  { get; set; } 
	public List<OppWrapper> opp90JeanetteList  { get; set; } 
	public List<OppWrapper> opp90KaraList  { get; set; }     
    public List<String> repNameList {get; set; }
    public Map<String, List<OppWrapper>> opp90Map {get; set; }  
    OppWrapper newOpp;
    
    public aggregateResult aggOppTotal {get; set;}
    decimal closedTotal;
    public decimal variance {get; set;}
    Rep_Goal__c goal;
    Decimal goalTotal;
    public Decimal oppTotal {get; set;}
    String UserId;
    public String userName {get; set;}    
    
    public GoalsOverView_Class() {
        repNameList = new List<String>{'Brit', 'Emma', 'Jeanette', 'Kara'};
        opp90Map = new Map<String, List<oppWrapper>>();
        UserId = UserInfo.getUserId();
        oppTotal = 0;
        closedTotal = 0;
        goalTotal = 0;
        Variance = 0;
               
            // top 10 all
                oppListStart = [SELECT Name, StageName, Owner.firstname, Id, Amount, account.id, account.name, type, closedate FROM Opportunity 
                                                  WHERE StageName = 'A. Pending Sale' AND Amount != 0 AND Amount != NULL AND OwnerID=:userID
                                                  ORDER BY Amount DESC LIMIT 10]; 
                aggOppTotal = [SELECT Sum(Amount) TotalAmount FROM Opportunity WHERE StageName = 'W. Win' AND CloseDate = THIS_QUARTER];
                goal = [SELECT Total_Revenue__c, Total_Margin__c, User__R.firstname FROM Rep_goal__c WHERE User__c = :userID AND Goals__r.Start_Date_of_new_Quarter__c = THIS_QUARTER]; 
                goalTotal = goal.Total_Revenue__c;
                closedTotal = (Decimal)aggOppTotal.get('TotalAmount');
 				opp90AllList = generateOppList(oppListStart, goalTotal, closedTotal);

    
        
          
        for(String repName:repNameList) {
               oppListStart = [SELECT Name, StageName, Owner.firstname, Id, Amount, account.id, account.name, type, closedate FROM Opportunity 
                                                  WHERE  Owner.firstname =:repName
                                                  ORDER BY Amount DESC LIMIT 10]; 
                aggOppTotal = [SELECT Sum(Amount) TotalAmount FROM Opportunity WHERE StageName = 'W. Win' AND CloseDate = THIS_QUARTER];
                goal = [SELECT Total_Revenue__c, Total_Margin__c, User__R.firstname FROM Rep_goal__c WHERE User__c = :userID AND Goals__r.Start_Date_of_new_Quarter__c = THIS_QUARTER]; 
                goalTotal = goal.Total_Revenue__c;
                closedTotal = (Decimal)aggOppTotal.get('TotalAmount');
 				opp90RepList = generateOppList(oppListStart, goalTotal, closedTotal); 
            opp90Map.put(repName, opp90RepList);
            
        }
        
        // Brit
        opp90BritList = opp90Map.get('Brit');
        opp90EmmaList = opp90Map.get('Emma');
        opp90JeanetteList = opp90Map.get('Jeanette');
        opp90KaraList = opp90Map.get('Kara');

       			

    }
    
    public List<OppWrapper> generateOppList(List<Opportunity> oppListStart, Decimal goalTotal, Decimal closedTotal) {
        	List<OppWrapper> oppList = new List<OppWrapper>();
            for (Opportunity opp:oppListStart) {
                system.debug('username=' + opp.owner.firstname);
                oppList.add(new OppWrapper(opp.owner.firstname, opp.account.name, opp.name,   opp.CloseDate, opp.Amount,  opp.id) );
                oppTotal = oppTotal + opp.amount;
            }
			if (goalTotal == NULL) {goalTotal = 0; } 
            if (closedTotal == NULL) {closedTotal = 0; }
        	oppList.add(new OppWrapper(NULL, NULL, 'Total Open Opp', NULL, OppTotal, NULL));
       		oppList.add(new OppWrapper(NULL, NULL, NULL, NULL, NULL, NULL));
       	    oppList.add(new OppWrapper(NULL, NULL, 'Total Closed Opp', NULL, closedTotal, NULL));
            oppList.add(new OppWrapper(NULL, NULL, 'Total Goal', NULL, goalTotal, NULL));
 
      	    return oppList;
    }
    

    
    public class OppWrapper {
        public String oppName {get; set; }
        public String acctName {get; set; }
        public String repName {get; set; }
        public Date closeDate {get; set; }
        public Decimal amount {get; set; }
        public String Id {get; set; }
        
        public  OppWrapper(String repName, String acctName, String oppName,  Date closedate, Decimal amount, String id) {
            this.oppName = oppName;
            this.closeDate = closeDate;
            this.amount = amount;
            this.id = id;
            this.acctname = acctName;
            this.repName = repName;
            

            
        }
    }  
    

}

 
Best Answer chosen by Mathew Andresen 5
logontokartiklogontokartik
From the error I see, I think there is some problem with the way Date is getting converted when putting it in a map. To isolate the issue, I would first change the Date type in your wrapper class to String and see if it resolves the issue?

All Answers

logontokartiklogontokartik
From the error I see, I think there is some problem with the way Date is getting converted when putting it in a map. To isolate the issue, I would first change the Date type in your wrapper class to String and see if it resolves the issue?
This was selected as the best answer
Mathew Andresen 5Mathew Andresen 5
I convereted the date to a string, but got a new error
"The value 'core.apexpages.el.adapters.RuntimeTypeMetadataELAdapter@42fd94ac' is not a valid number."
Mathew Andresen 5Mathew Andresen 5
I traced the error down to my amount variable.  For whatever reason it didn't like it.  I renamed it total, and now it's working.

Thanks for the help!

Below the code  (note, the hiarachy is now actually map, wrapper, list
 
<table width ="100%">
            <tr>
            
    
    <apex:repeat value="{!opp90Map}" var="key">
        <!--<apex:outputtext> {!opp90Map}</apex:outputtext><br/>-->
        
        <apex:repeat value="{!opp90Map[key]}" var="wrapper">
         <!--   <apex:outputtext> {!opp90Map[key]}</apex:outputtext><br/>-->
        <td width="25%" valign="top">    
      <apex:pageblock >      
    <apex:pageBlockTable  value="{!wrapper.wrapperList}" var="opp">
                 <apex:column >
         <apex:facet name="header">Rep</apex:facet>
             <apex:outputtext >{!opp.repName}</apex:outputtext>
         </apex:column>
         <apex:column >
         <apex:facet name="header">Account</apex:facet>
             <apex:outputtext >{!opp.acctName}</apex:outputtext>
         </apex:column>         
         <apex:column > 
            <apex:outputText value="{!opp.CloseDate}"> </apex:outputText>
             <apex:facet name="header">Date</apex:facet>
         </apex:column>
           <apex:column >
            <apex:facet name="header">Opportunity</apex:facet>
        <apex:outputLink value="{!if(opp.id != NULL, URLFOR($Action.Opportunity.View, opp.Id), NULL) }" > {!opp.oppName} </apex:outputLink>
                    <apex:facet name="footer" ><apex:outputPanel > Variance: &nbsp; 
        </apex:outputPanel> </apex:facet>
        </apex:column>
          <apex:column >
            <apex:facet name="header" >Amount</apex:facet>
            <apex:outputText value="{0,number,$###,###,##0}">
            <apex:param value="{!opp.Total}"/> </apex:outputText> 
            <apex:facet name="footer" >
            <apex:outputText value="{0,number,$###,###,##0}">
            <apex:param value="{!wrapper.variance}"/> </apex:outputText> 
            </apex:facet>  
        </apex:column>
   
        </apex:pageBlockTable>
        </apex:pageblock>
            </td>
            </apex:repeat>
    </apex:repeat>
            </tr>
    </table>