• sunnysharma85
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies

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
leadsToUpdate.add(t.WhoId);
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 ])
{
updateLeads.add(currLead);
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())
Database.update(updateLeads);

}