function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ 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')..