+ Start a Discussion
Bayarea 101Bayarea 101 

lead activity counter

i am trying to update a field on Lead object based on activity. Here is the code. When i create an acitvity on leads this field remain blank. Am i missing something. 
trigger UpdateLeadCounts on Task (after delete, after insert, after undelete, after update) {

set<ID> LeadIds= new Set<ID>();
for(Task tt:trigger.new)
{
if(tt.whoId!=null && string.valueof(tt.WhoId).startsWith('003'))
{

LeadIDs.add(tt.whoID);
}
}

if(LeadIds.isEmpty())
return;
List<Lead> cnts= new List<Lead>();

Integer number1=1;
for(Lead ct:[select id, name, count1__c from Lead where id in:Leadids])
{

if(ct.count1__c ==null)
ct.count1__c=0;

ct.count1__c=ct.count1__c+number1;


cnts.add(ct);
}

if(cnts.size()>0)
{
update cnts;
}
}
 
Best Answer chosen by Bayarea 101
Saikishore Reddy AengareddySaikishore Reddy Aengareddy
change .startsWith('003') to .startsWith('00Q')..