0

I am stuck with a bit of code - is someone able to help with this? For the 8th line of code, I'm getting a variable doesn't exist error. I have been starting at this far too long, so cannot see what's wrong.

EDIT: I have now updated my code, and now I am getting another error for: leadsToUpdateById.put(tmpLead); it says incorrect signature.

public static void copyFirstCallDate(List triggerNew) {

    Map<Task,Id> leadIdsByTasks = new Map<Task,Id>();
    for (Task t : triggerNew) {
        if (t.Status == 'Completed') {
           leadIdsByTasks.put(t, t.WhoId); 
        }
    }

    Map<Id,Lead> leadsToUpdateById = new Map<Id,Lead>([SELECT Id, X1st_Call__c FROM Lead WHERE Id IN: leadIdsByTasks.values()]); 

    for (Task t : triggerNew) {
        if (leadIdsByTasks.containsKey(t)) {
            Id lId = leadIdsByTasks.get(t);
            Lead tmpLead = leadsToUpdateById.get(lId);
            tmpLead.X1st_Call__c = t.Closed_Date__c;
            leadsToUpdateById.put(tmpLead);
        }
    }
    if ( !leadsToUpdateById.values().isEmpty()) {
        update leadsToUpdateById.values();
    }
}

Tia

2 Answers 2

1

I think you want to replace whoIds.getValues() by leadIdsByTasks.getValues(). Looks like you may have refactored and forgot to change the name.

3
  • oh, and it should be leadIdsByTasks.values()
    – Lily
    Commented Nov 6, 2014 at 16:53
  • EDIT: I have now updated my code, and now I am getting another error for: leadsToUpdateById.put(tmpLead); it says incorrect signature.
    – Lily
    Commented Nov 6, 2014 at 17:04
  • 1
    Put requires two parameters. The key and value. Key should be the lead's ID.
    – sfdcfox
    Commented Nov 6, 2014 at 20:20
1

It should be, map requires key value pair.

leadsToUpdateById.put(tmpLead.id, tmpLead);

2
  • Cool. my first answer. Glad you solved it. Commented Nov 6, 2014 at 17:13
  • Lily, as you changed your question both answers are valid. Could you select either (to the left of it) as accepted answer so that it's indicated that this has been resolved ? I'd suggest you accept this answer as Sforce Ninja can use some reputation :-). Commented Nov 6, 2014 at 23:38

You must log in to answer this question.

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