+ Start a Discussion

Why Is This Not Working!!

Hi All,


I have 'manipulated' a previous trigfger used on the Task/Leads object which effectivly marks a checkbox on the Lead object if an associated task is Not Started and in the future. I want to utilise this same functionality for Accounts and related Tasks as well. I think I changed the correct parts of the trigger, however it dosnt trigger! Any ideas would be most appreciated.


trigger FlagFutureTasks on Task (after insert, after update) {

Set<Id> leadsToUpdate = new Set<Id>{};
String leadPrefix = Account.SObjectType.getDescribe().getKeyPrefix();

for(Task t : trigger.new)
if(t.WhoId != null && ((String)t.WhoId).startsWith(leadPrefix))  //if not null and whoId belongs to a Lead
List<Account> updateLeads = new List<Account>{};

for (Account currLead : [Select Id,Has_Future_Scheduled_Activity__c, (Select Id, Status, ActivityDate, Outcome__c from Tasks ORDER BY CreatedDate DESC) from Account where Id IN :leadsToUpdate ])
currLead.Has_Future_Scheduled_Activity__c = false;

for(Task t : currLead.Tasks )

if(t.ActivityDate > Date.Today() && t.Status == 'Not Started')
currLead.Has_Future_Scheduled_Activity__c = true;

}//end inner for
}//end outer for

if (updateLeads != null && !updateLeads.isEmpty())






Check the description of whoID. It states:

ID of a related Contact or Lead. If the WhoId refers to a lead, then the WhatId field must be empty. Label is Contact/Lead ID. If Shared Activities is enabled, this is the ID of a related Lead or primary Contact.


You need to use whatId or AccountId field for comparison.

Anup JadhavAnup Jadhav

Shouldn't line 3 be:


String leadPrefix = Lead.SObjectType.getDescribe().getKeyPrefix();

 Instead of Account.sobjecttype.....


- anup