You need to sign in to do that
Don't have an account?
Raghu Cheruvu 1
Incompatible value type Object for Map
Hi,
I am adding getting following error while adding the elements to a map.
Error:- Incompatible value type Object for Map
Code:-
public class CR_Report{
public void Completed_CR_Report(){
//Compare old zip on account with the new zip.. if it is different insert the record into
// CR_Audit_Move__c
List<Change_Request_MDV__c> CRCompletedList=new List<Change_Request_MDV__c>([Select Account__c,Name,Status__C,Reason__c,
New_Territory__c,Zip_MDVN__c, State_MDVN__c,CreatedDate,LastModifiedDate
from Change_Request_MDV__c
where Status__C='On Hold'
and Reason__c in ('Completed')
and LastModifiedDate=Today]);
Map<String,String> AccCRMap=new Map<String,String>();
for(Change_Request_MDV__c c: CRCompletedList){
AccCRMap.put(c.Account__c,c.Id);
}
List<Account> AccCRList=new List<Account>([Select Id from Account
where ID IN:AccCrMap.keyset()]);
Map<String,String> OldAccMap=new Map<String,String>();
Map<String,String> NewAccMap=new Map<String,String>();
List<AccountHistory> AccHistoryList=new List<AccountHistory>([Select AccountId,oldvalue,newvalue from
AccountHistory
where field='Territory_vod__c'
and AccountId IN:AccCrMap.keyset()]);
for(AccountHistory ah:AccHistoryList){
oldAccMap.put(ah.AccountId,ah.oldvalue);//>>>>>>>>>>>>>>>> Error Line<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
//NewAccMap.put(ah.AccountId,ah.newvalue);
}
}
}
I am adding getting following error while adding the elements to a map.
Error:- Incompatible value type Object for Map
Code:-
public class CR_Report{
public void Completed_CR_Report(){
//Compare old zip on account with the new zip.. if it is different insert the record into
// CR_Audit_Move__c
List<Change_Request_MDV__c> CRCompletedList=new List<Change_Request_MDV__c>([Select Account__c,Name,Status__C,Reason__c,
New_Territory__c,Zip_MDVN__c, State_MDVN__c,CreatedDate,LastModifiedDate
from Change_Request_MDV__c
where Status__C='On Hold'
and Reason__c in ('Completed')
and LastModifiedDate=Today]);
Map<String,String> AccCRMap=new Map<String,String>();
for(Change_Request_MDV__c c: CRCompletedList){
AccCRMap.put(c.Account__c,c.Id);
}
List<Account> AccCRList=new List<Account>([Select Id from Account
where ID IN:AccCrMap.keyset()]);
Map<String,String> OldAccMap=new Map<String,String>();
Map<String,String> NewAccMap=new Map<String,String>();
List<AccountHistory> AccHistoryList=new List<AccountHistory>([Select AccountId,oldvalue,newvalue from
AccountHistory
where field='Territory_vod__c'
and AccountId IN:AccCrMap.keyset()]);
for(AccountHistory ah:AccHistoryList){
oldAccMap.put(ah.AccountId,ah.oldvalue);//>>>>>>>>>>>>>>>> Error Line<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
//NewAccMap.put(ah.AccountId,ah.newvalue);
}
}
}
try declaring like this. It will work.
Map<ID,String> OldAccMap=new Map<ID,String>();
Map<ID,String> NewAccMap=new Map<ID,String>();
Or
While adding to Map Concat emptry string (This depends on the purpose of Map)
Thanks
Sid
I tried using the below decalration:-
Map<Id, String> OldAccMap=new Map<String,String>();
When i tried to add elements to the map i still get the same error.
Try type casting.,
Change the statement
oldAccMap.put(ah.AccountId,ah.oldvalue)
to
oldAccMap.put(string.valueof(ah.AccountId),String.valueOf(ah.oldvalue))
and see if it works.,
Thanks,
balaji
Hi
Sorry Your mistaken in declaraation of Map. Please declare as
Map<Id, String> OldAccMap=new Map<Id,String>();
Not
Map<Id, String> OldAccMap=new Map<String,String>();
It should work.This will sort your problem
Thanks
Sid
I had mistyped the declaration,
The declaration I had was:-
Map<Id, String> OldAccMap=new Map<Id,String>();
but still i am getting the same error message..