I have a custom object Relationship_Owner__C with a lookup relationship to Contacts. I need to query all the contacts that belong to the relationship owner, and all the tasks assigned to the contact in order to get a count of unique subject lines.
When I tried to break it into two queries I got a SOQL 101 error. But now I seem to be stuck on making it work at all. Any help would be great.
trigger CountUniqueEmails on relationship_owner__c (before insert, before update) {
LIST<Task> taskList =[SELECT ID,
(SELECT Id,
Subject
FROM Tasks)
FROM Contact
WHERE New_Relationship_owner1__c IN :Trigger.New];
system.debug('Influencers found =:' + taskList.size());
//If the list size is greater than 0 get the tasks assigned to the influencers
If(taskList.size() !=0){
String subject = 'none';
Integer uniqueCount = 0;
New Code
trigger CountUniqueEmails on relationship_owner__c (after insert, after update){
Map contactMap = new Map([SELECT Id, New_Relationship_owner1__c
FROM Contact
WHERE New_Relationship_owner1__c IN :Trigger.newMap.keySet()]);
List taskList = [SELECT Id, WhoId,Subject
FROM Task
WHERE WhoId IN :contactMap.keySet()];
Map> subjectLineMap = new Map>();
for(Task t: taskList) {
Id relationshipOwnerId = contactMap.get(t.WhoId).New_Relationship_owner1__c;
if(!subjectLIneMap.containsKey(relationshipOwnerId)){
subjectLineMap.put(relationshipOwnerId, new Set<String>());
}
subjectLineMap.get(relationshipOwnerId).add(t.Subject);
system.debug('unique subject count=' + subjectLineMap.size());
}
}