0

I am trying to get wrapper class records into variables but getting the error as:

Initial term of field expression must be a concrete SObject: String

class wrapperDateData {
   public String curDate {get;set;}
   public Integer count {get;set;}
}

    wrapperDateData w = null;
    Map<String, wrapperDateData> mapWrapper = new Map<String, wrapperDateData>();

        for (AggregateResult ar : [Select Count(id) c, HLA_Expiration_Date__c exp from Hardware_Loan_Agreement__c where HLA_Expiration_Date__c>=:Date.today() and HLA_Expiration_Date__c<:Date.today().addDays(5) and Primary_Status__c = 'Proposal' Group By HLA_Expiration_Date__c Order by HLA_Expiration_Date__c]) 
                    {
                    String cdate = ((Date)ar.get('exp')).format();
                        Integer count = (Integer)ar.get('c');

                        if(mapWrapper.containsKey(cdate)) {
                            w = mapWrapper.get(cdate);
                            w.count += count;
                        } else {
                            w = new wrapperDateData();
                            w.curDate = cdate;
                            w.count = count;
                            mapWrapper.put(cdate, w);
                        }
                    }
        System.debug('Test - ' + mapWrapper);

    Integer count = 1;
    public String date1;
    public String date2;
    public String date3;
    public String date4;
    public String date5;

    public Integer cnt1;
    public Integer cnt2;
    public Integer cnt3;
    public Integer cnt4;
    public Integer cnt5;
        for(String wrap : mapWrapper.keyset())
        {
          if(count ==1){
                date1 = mapWrapper.get(wrap.curDate);
                cnt1 = wrap.count; 
            }else if (count == 2){
                date2 = mapWrapper.get(wrap.curDate);
                cnt2 = wrap.count; 
            }else if (count == 3){
                date3 = mapWrapper.get(wrap.curDate);
                cnt3 = wrap.count;
            }else if (count == 4){
                date4 = mapWrapper.get(wrap.curDate);
                cnt4 = wrap.count;
            }else if (count == 5){
                date5 = mapWrapper.get(wrap.curDate);
                cnt5 = wrap.count;
            }
            count++;

        }
        System.debug('date1'+date1);
        System.debug('cnt1'+cnt1);
        System.debug('date2'+date2);
        System.debug('cnt2'+cnt2);
        System.debug('date3'+date3);
        System.debug('cnt3'+cnt3);
        System.debug('date4'+date4);
        System.debug('cnt4'+cnt4);
        System.debug('date5'+date5);
        System.debug('cnt5'+cnt5);

I am getting this error for below section:-

for(String wrap : mapWrapper.keyset())
    {
      if(count ==1){
            date1 = mapWrapper.get(wrap.curDate);
            cnt1 = wrap.count; 
        }else if (count == 2){
            date2 = mapWrapper.get(wrap.curDate);
            cnt2 = wrap.count; 
        }else if (count == 3){
            date3 = mapWrapper.get(wrap.curDate);
            cnt3 = wrap.count;
        }else if (count == 4){
            date4 = mapWrapper.get(wrap.curDate);
            cnt4 = wrap.count;
        }else if (count == 5){
            date5 = mapWrapper.get(wrap.curDate);
            cnt5 = wrap.count;
        }
        count++;

    }
2
  • Please try posting your apex class in some better readable format. Also provide definition of wrapper class and exact line number where error was reported. Commented Feb 3, 2017 at 9:25
  • Sorry for that. Done.
    – Sharma_raj
    Commented Feb 3, 2017 at 9:35

1 Answer 1

1

Can you try this code. Since wrap is a String variable, you cannot call wrap.curDate. You need to get wrapperDateData value from mapWrapper by using this string as a key.

for(String wrap : mapWrapper.keyset())
{
    if(count ==1){
        date1 = mapWrapper.get(wrap).curDate;
        cnt1 = mapWrapper.get(wrap).count; 
    }else if (count == 2){
        date2 = mapWrapper.get(wrap).curDate;
        cnt2 = mapWrapper.get(wrap).count;
    }else if (count == 3){
        date3 = mapWrapper.get(wrap).curDate;
        cnt3 = mapWrapper.get(wrap).count;
    }else if (count == 4){
        date4 = mapWrapper.get(wrap).curDate;
        cnt4 = mapWrapper.get(wrap).count;
    }else if (count == 5){
        date5 = mapWrapper.get(wrap).curDate;
        cnt5 = mapWrapper.get(wrap).count;
    }
    count++;
}
0

You must log in to answer this question.

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