+ Start a Discussion
iKnowSFDCiKnowSFDC 

Invalid Integer Error

I'm running into this error: Invalid integer: common.apex.runtime.impl.ScalarList@b5144800 when executing the following code.  The code compiles with no problem.  I'm fairly certain I have my data types correct - not really sure what's causing this? Any ideas? 

 

   public Map<Target_HCP__c, Integer> targetsWithCalls = new Map<target_HCP__c, Integer>();
        
    public void updateCalls(){
            Map<Id, Integer> acctCalls = new Map<Id, Integer>();
            List<AggregateResult> r = [SELECT Account_vod__c acctid, COUNT(id) totalCalls
                           FROM Call2_vod__c 
                           WHERE Call_Date_vod__c =THIS_QUARTER
                           AND Status_vod__c = 'Submitted_vod'                            
                           GROUP BY Account_vod__c];
            for(AggregateResult i : r){
                acctCalls.put(String.valueOf(i.get('acctId')), integer.valueOf(i.get('totalCalls')));
                system.debug(' account>>> ' + i.get('acctid') + 'number of calls>>> '+i.get('totalCalls'));
            }  
           
   
         
         for(Target_HCP__c t : [SELECT id, Calls_Actual__c, Prescriber__c 
                                     FROM Target_HCP__c 
                                     WHERE Prescriber__c = :acctCalls.KeySet()]){
             targetsWithCalls.put(t, integer.valueOf(acctCalls.Values()));
             t.Calls_Actual__c += integer.valueOf(targetsWithCalls.Values());
             targetsToUpdate.add(t);
         }
            update targetsToUpdate;                     
         }

 

 

Best Answer chosen by Admin (Salesforce Developers) 
Imran MohammedImran Mohammed

The Map you created stores an Integer and the map.values(acctCalls.Values()) will always return list of Integers.

You should probably iterate over acctCalls.Values() and add the Integer values to the Map as below.

for(Integer iVal: acctCalls.Values())

{

targetsWithCalls.put(t, iVal));// there is no need to typecast again to integer here

//code here

}