You need to sign in to do that
Don't have an account?

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 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); }
http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_task.htm
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.
Shouldn't line 3 be:
Instead of Account.sobjecttype.....
- anup