You need to sign in to do that
Don't have an account?

Help for Activity Trigger on Contact AND Account record(s)
Hello all...
Looking for some assistance on a trigger i'm writing...
Basically, I have a trigger that will update an Account Status and Stage (custom field) based on the completion of an Activity. I wrote the trigger initially based on the completed activity being logged on the Account record. When I realized I also needed to accomplish the same functionality if an activity is completed against a Contact (oopsies) within said Account, I modified the trigger to the below:
trigger changeAccountStagetask1 on Task (before update, after update) {
Set<String> whatIDs = new Set<String>();
for (Task tsk: Trigger.new) {
whatIDs.add(tsk.whatID);
}
List<Contact> conlist = [SELECT Id, AccountId FROM Contact WHERE accountId in :whatIDs];
List<Account> filteredAccts = new List<Account>();
Map<Id, Account> accts = new Map<Id, Account>();
Map<String, Task> taskMap = new Map<String, Task>();
for (Task tsk: Trigger.new) {
if(taskMap.containsKey(tsk.whatId)) {
if(tsk.Status=='Completed' && tsk.Subject=='Call To Qualify (Successful)'){
Account ld = new Account(Id=tsk.whatID);
ld.Status__c = 'Qualified Prospect';
ld.Stage__c = 'Need To Set Meeting';
taskMap.put(tsk.whatID, tsk);
}
}
update accts.values();
}
}
However, when I attempt to test this trigger in my Sandbox, nothing changes...whether I log the call on the Account, or on the Contact, the Status/Stage doesn't change...and no errors are coming up...any thoughts on what I'm missing based on my code above?
Thanks so much in advance for your help!!!
E
Looking for some assistance on a trigger i'm writing...
Basically, I have a trigger that will update an Account Status and Stage (custom field) based on the completion of an Activity. I wrote the trigger initially based on the completed activity being logged on the Account record. When I realized I also needed to accomplish the same functionality if an activity is completed against a Contact (oopsies) within said Account, I modified the trigger to the below:
trigger changeAccountStagetask1 on Task (before update, after update) {
Set<String> whatIDs = new Set<String>();
for (Task tsk: Trigger.new) {
whatIDs.add(tsk.whatID);
}
List<Contact> conlist = [SELECT Id, AccountId FROM Contact WHERE accountId in :whatIDs];
List<Account> filteredAccts = new List<Account>();
Map<Id, Account> accts = new Map<Id, Account>();
Map<String, Task> taskMap = new Map<String, Task>();
for (Task tsk: Trigger.new) {
if(taskMap.containsKey(tsk.whatId)) {
if(tsk.Status=='Completed' && tsk.Subject=='Call To Qualify (Successful)'){
Account ld = new Account(Id=tsk.whatID);
ld.Status__c = 'Qualified Prospect';
ld.Stage__c = 'Need To Set Meeting';
taskMap.put(tsk.whatID, tsk);
}
}
update accts.values();
}
}
However, when I attempt to test this trigger in my Sandbox, nothing changes...whether I log the call on the Account, or on the Contact, the Status/Stage doesn't change...and no errors are coming up...any thoughts on what I'm missing based on my code above?
Thanks so much in advance for your help!!!
E
I tried your suggestion above, but I keep getting errors:
Error: Compile Error: No such column 'ContactId' on entity 'Contact'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names. at line 17 column 29
Thanks
Thanks so much for your help...I'm still missing something...below is my code:
trigger changeAccountStagetask1 on Task (before update, after update) {
Set<String> whatIDs = new Set<String>();
for (Task tsk: Trigger.new) {
whoIDs.add(tsk.whoID);
}
List<Contact> conlist = [SELECT Id, AccountId FROM Contact WHERE Id in :whoIDs];
List<Account> filteredAccts = new List<Account>();
Map<Id, Account> accts = new Map<Id, Account>();
Map<String, Task> taskMap = new Map<String, Task>();
for (Task tsk: Trigger.new) {
if(taskMap.containsKey(tsk.whatId)) {
if(tsk.Status=='Completed' && tsk.Subject=='Call To Qualify (Successful)'){
Account ld = new Account(Id=tsk.whatID);
ld.Status__c = 'Qualified Prospect';
ld.Stage__c = 'Need To Set Meeting';
taskMap.put(tsk.whatID, tsk);
}
}
update accts.values();
}
}
Now the error is: Error: Compile Error: Variable does not exist: whoIDs at line 8 column 77
I keep trying to change, but still reverts back to this error....Thoughts?
Thanks again!!!
I'm still fairly new to triggers so i'm sure I'm missing something fairly obvious, lol...