2

Having the error in the title and cant see whats wrong at all:

Map<String, List<Contact>> taskContactsMap = new Map<String, List<Contact>>{};
for(TaskRelation tr : taskRels)
{
    List<Contact> contactList = new List<Contact>{};
    for(Contact contact : contacts)
    {
        if(contact.Id == tr.RelationId)
        {
            contactList.add(contact);
        }
    }

    taskContactsMap.put(tr.TaskId, contactList);
}

for(Task item : tasks)
{
    DealActivityData activityData = new DealActivityData(item, taskContactsMap.get(task.Id));

    config.addItem(new DealActivity(activityData, currentMapping), item.IsClosed);  
}

Its pretty simple. Making an array of Contacts and trying to put them in a map with the Task Id as the key. When I compile though I get

Incompatible key type Schema.SObjectField for Map<String, List<Contact>>

Its the taskContactsMap.get(task.Id) line thats causing the issue

3
  • Is it this line causing the problem? taskContactsMap.put(tr.TaskId, contactList); If so, double check that tr.TaskId is indeed an Id. It looks like is should be, but the error is indicating otherwise. Nov 17, 2016 at 21:47
  • No its the taskContactsMap.get(task.Id). Ill update the post Nov 17, 2016 at 21:48
  • Can you split it out to List<Contact> contacts = taskContactsMap.get(task.Id);? Looks like it should work. Nov 17, 2016 at 21:50

1 Answer 1

5

Change the following line:

DealActivityData activityData = new DealActivityData(item, taskContactsMap.get(task.Id));

to:

DealActivityData activityData = new DealActivityData(item, taskContactsMap.get(item.Id));

The for loop is using item rather than task as the loop variable.

It's complaining about Schema.SObjectField as Task.Id is getting metadata for the Id field on Task. E.g. System.debug(Task.Id);

2
  • 1
    Cheers. Christ, silly to miss that, ill blame it on it being the end of the day. Thanks. Nov 17, 2016 at 21:52
  • No problem. Took it a few goes to spot it :) Nov 17, 2016 at 21:54

You must log in to answer this question.

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