+ Start a Discussion
Vandana Rattan 4Vandana Rattan 4 

Incompatible key type Object for Map<Id,Id>

I am trying to query OpportunityContactRole for contacts and poulating the results in a mapwith ContactId as key and OpportunityId as value. I keep on geeting compilation error Incompatible key type Object for Map<Id,Id> in the line where I am polulating mpCtIdOppId. Kindly suggest.
 
Map<Id,Id> mpCtIdOppId = new Map<Id,Id>();
        Map<Id,List<OpportunityContactRole>> mpCtIdOppCtRl = new Map<Id,List<OpportunityContactRole>>();
        List<OpportunityContactRole> lstOppCtRole = [Select OpportunityId, ContactId from OpportunityContactRole where ContactId in: scope];
        System.debug('lstOppCtRole >>>' + lstOppCtRole);
        
        for(OpportunityContactRole oppctrl1: lstOppCtRole){
            System.debug('oppctrl1 contactid >>>' + oppctrl1.get('ContactId'));
            mpCtIdOppId.put(oppctrl1.get('ContactId'), oppctrl1.get('OpportunityId'));
        }

 
Best Answer chosen by Vandana Rattan 4
Deepak Maheshwari 7Deepak Maheshwari 7

Hi Vandana,

 

Please use below line:

mpCtIdOppId.put(oppctrl1.ContactId, oppctrl1.OpportunityId);

All Answers

Deepak Maheshwari 7Deepak Maheshwari 7

Hi Vandana,

 

Please use below line:

mpCtIdOppId.put(oppctrl1.ContactId, oppctrl1.OpportunityId);

This was selected as the best answer
Vandana Rattan 4Vandana Rattan 4
Thank you!!!