You need to sign in to do that
Don't have an account?
Brooks Johnson 6
Help With Trigger to Count Unique Tasks
trigger CountUniqueEmails on relationship_owner__c (before insert, before update) {
for (Relationship_Owner__c rOwner : trigger.new){
//get list of on tasks belonging to owner that contain "Pardot"
LIST<Task> taskList = [SELECT ID,
Subject
FROM Task
WHERE Subject LIKE 'Pardot'
AND WhoId = :rOwner.Id];
system.debug(taskList.size() + 'Matching tasks found');
//if matches are found
if(!tasklist.isEmpty()){
String pardotSubject = 'none';
Integer uniqueCount = 0;
//loop through matches and increment count if unqique
for( Task t : taskList){
if( pardotSubject != t.Subject){
uniqueCount = uniqueCount +1;
system.debug('Unique count' + uniqueCount);
}
rOwner.Unique_Emails_Sent__c = uniqueCount;
insert rOwner;
}
}
}
//need a list of all tasks that contain pardot that belong to the relationship owner
//Loop through tasks to a get a count of unique subjects
//Update Relationship Owner.
}
for (Relationship_Owner__c rOwner : trigger.new){
//get list of on tasks belonging to owner that contain "Pardot"
LIST<Task> taskList = [SELECT ID,
Subject
FROM Task
WHERE Subject LIKE 'Pardot'
AND WhoId = :rOwner.Id];
system.debug(taskList.size() + 'Matching tasks found');
//if matches are found
if(!tasklist.isEmpty()){
String pardotSubject = 'none';
Integer uniqueCount = 0;
//loop through matches and increment count if unqique
for( Task t : taskList){
if( pardotSubject != t.Subject){
uniqueCount = uniqueCount +1;
system.debug('Unique count' + uniqueCount);
}
rOwner.Unique_Emails_Sent__c = uniqueCount;
insert rOwner;
}
}
}
//need a list of all tasks that contain pardot that belong to the relationship owner
//Loop through tasks to a get a count of unique subjects
//Update Relationship Owner.
}
trigger CountUniqueEmails on relationship_owner__c (before insert, before update) { for (Relationship_Owner__c rOwner : trigger.new){ //get list of on tasks belonging to owner that contain "Pardot" LIST<Task> taskList = [SELECT ID, Subject FROM Task WHERE Subject LIKE 'Pardot' AND WhoId = :rOwner.Id]; system.debug(taskList.size() + 'Matching tasks found'); //if matches are found if(!tasklist.isEmpty()){ String pardotSubject = 'none'; Integer uniqueCount = 0; //loop through matches and increment count if unqique for( Task t : taskList){ if( pardotSubject != t.Subject){ uniqueCount = uniqueCount +1; system.debug('Unique count' + uniqueCount); } rOwner.Unique_Emails_Sent__c = uniqueCount; insert rOwner; } } } //need a list of all tasks that contain pardot that belong to the relationship owner //Loop through tasks to a get a count of unique subjects //Update Relationship Owner. }
And I am still stuck on my problem of how to traverse from Relationship Owner__c to Contact to Task.