You need to sign in to do that
Don't have an account?
Bayarea 101
Contacted counter for Contacts
I need to create a field on contact. It should be recording how many time this contact has been contacted. Based on the activity history and put it as number on contact counter how many time the contact has been contacted.
Create one field on Contact with APIName:count1__c .
TriggerCode:
trigger updateContactCounts on Task (after insert, after update) {
set<ID> contactIds= new Set<ID>();
for(Task tt:trigger.new)
{
if(tt.whoId!=null && string.valueof(tt.WhoId).startsWith('003'))
{
contactIDs.add(tt.whoID);
}
}
if(contactIds.isEmpty())
return;
List<Contact> cnts= new List<Contact>();
Integer number1=1;
for(Contact ct:[select id, name, count1__c from contact where id in:contactids])
{
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;
}
}
[Error] Error: Compile Error: Loop variable must be of type SOBJECT:Contact at line 4 column 10
trigger UpdateLeadCounts on Task (after insert, 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;
}
}