You need to sign in to do that
Don't have an account?
Shauna Davies 72
I am working on a "count" trigger for tasks in a Contact. I want to count tasks initiated by User Profile. Here is the code:
trigger UpdateAEContactActivities on Task (after update) {
set<ID> ContactIds= new Set<ID>();
for(Task tt:trigger.new){
if(UserInfo.getProfileId()=='Standard Sales User'){
if(tt.Subject.containsIgnoreCase('Call (Completed)') || tt.Subject.containsIgnoreCase('Call (Left Message)') || tt.Subject.containsIgnoreCase('Call (No Answer)') || tt.Subject.containsIgnoreCase('Call (Incoming)') || tt.Subject.containsIgnoreCase('Email - &') || tt.Subject.containsIgnoreCase('LinkedIn') || tt.Subject.containsIgnoreCase('[Sendbloom]')){
if(tt.Status.equals('Completed')){
ContactIDs.add(tt.whoID);
}
}
}
}
if(ContactIds.isEmpty())
return;
if(stoprecurssionupdate.runonce()){
List<Contact> cnts= new List<Contact>();
Integer number1=1;
for(Contact ct:[select id, name, AE_Activities_Counter__c from Contact where id in:Contactids])
{
if(ct.AE_Activities_Counter__c ==null)
ct.AE_Activities_Counter__c=0;
ct.AE_Activities_Counter__c=ct.AE_Activities_Counter__c+number1;
cnts.add(ct);
}
if(cnts.size()>0)
{
update cnts;
}
}}
The code keeps returning an error on line 5... I know I don't have the syntax correct....
set<ID> ContactIds= new Set<ID>();
for(Task tt:trigger.new){
if(UserInfo.getProfileId()=='Standard Sales User'){
if(tt.Subject.containsIgnoreCase('Call (Completed)') || tt.Subject.containsIgnoreCase('Call (Left Message)') || tt.Subject.containsIgnoreCase('Call (No Answer)') || tt.Subject.containsIgnoreCase('Call (Incoming)') || tt.Subject.containsIgnoreCase('Email - &') || tt.Subject.containsIgnoreCase('LinkedIn') || tt.Subject.containsIgnoreCase('[Sendbloom]')){
if(tt.Status.equals('Completed')){
ContactIDs.add(tt.whoID);
}
}
}
}
if(ContactIds.isEmpty())
return;
if(stoprecurssionupdate.runonce()){
List<Contact> cnts= new List<Contact>();
Integer number1=1;
for(Contact ct:[select id, name, AE_Activities_Counter__c from Contact where id in:Contactids])
{
if(ct.AE_Activities_Counter__c ==null)
ct.AE_Activities_Counter__c=0;
ct.AE_Activities_Counter__c=ct.AE_Activities_Counter__c+number1;
cnts.add(ct);
}
if(cnts.size()>0)
{
update cnts;
}
}}
The code keeps returning an error on line 5... I know I don't have the syntax correct....
You are checking the profileid with name .
change this condition if(UserInfo.getProfileId()=='Standard Sales User'){ in place of Profile name put profileid.
Thanks
Anil.B
All Answers
You are checking the profileid with name .
change this condition if(UserInfo.getProfileId()=='Standard Sales User'){ in place of Profile name put profileid.
Thanks
Anil.B
It still does not update the field by an increment of 1, when I add a Task.... I am not sure why....
trigger UpdateAEContactActivities on Task (after update) {
set<ID> ContactIds= new Set<ID>();
for(Task tt:trigger.new){
if(UserInfo.getProfileId()=='00e00000006t1rl'){
if(tt.Subject.containsIgnoreCase('Call (Completed)') || tt.Subject.containsIgnoreCase('Call (Left Message)') || tt.Subject.containsIgnoreCase('Call (No Answer)') || tt.Subject.containsIgnoreCase('Call (Incoming)') || tt.Subject.containsIgnoreCase('Email - &') || tt.Subject.containsIgnoreCase('LinkedIn') || tt.Subject.containsIgnoreCase('[Sendbloom]')){
if(tt.Status.equals('Completed')){
ContactIDs.add(tt.whoID);
}
}
}
}
if(ContactIds.isEmpty())
return;
if(stoprecurssionupdate.runonce()){
List<Contact> cnts= new List<Contact>();
Integer number1=1;
for(Contact ct:[select id, name, AE_Activities_Counter__c from Contact where id in:Contactids])
{
if(ct.AE_Activities_Counter__c ==null)
ct.AE_Activities_Counter__c=0;
ct.AE_Activities_Counter__c=ct.AE_Activities_Counter__c+number1;
cnts.add(ct);
}
if(cnts.size()>0)
{
update cnts;
}
}}
Change the trigger to after insert and try once.
Thanks
Anil.B
Try these code,there might be some typo errors :-
Thanks
Anil.B
The code did not work, and I am also receiving errors on the Profile ID: " duplicate values on record with ID"......I tired it with the Profile ID set to "Standard Sales User" and " 00e00000006t1rl".
Shauna
Can you paste the full error message and your code.
Thanks
Anil.B