You need to sign in to do that
Don't have an account?
Rick Rossi
Trigger question on the task
I am running into issues on my trigger that is failing: It is supposed to prevent task creation related to an "inactive" contact and any time a user tries to create a task for an "inactive" contact. Any help would be great, this is what I have so far.
trigger TaskTrigger on Task (before insert, before update) {
set<id>Ctids=new set<id>();
for(task t:trigger.new){
Ctids.add(t.whatid);
}
if(!ctids.isempty()){
List<Contact>lstacc=[select id,Status__c from contact where id in:ctids AND Status__c =:'Active'];
Map<id,String>mapofcts=new Map<id,string>();
for(Contact record: contacts) {
mapofaccts.put(ct.id,Ct.Status__c);
}
for(task t:trigger.new){
if(mapofaccts.containsKey(t.whatid)){
t.addError ('Cannot Create a task For An In-Active Contact');
}
}
}
}
trigger TaskTrigger on Task (before insert, before update) {
set<id>Ctids=new set<id>();
for(task t:trigger.new){
Ctids.add(t.whatid);
}
if(!ctids.isempty()){
List<Contact>lstacc=[select id,Status__c from contact where id in:ctids AND Status__c =:'Active'];
Map<id,String>mapofcts=new Map<id,string>();
for(Contact record: contacts) {
mapofaccts.put(ct.id,Ct.Status__c);
}
for(task t:trigger.new){
if(mapofaccts.containsKey(t.whatid)){
t.addError ('Cannot Create a task For An In-Active Contact');
}
}
}
}
Please change t.WhatId to t.WhoId
I hope this help
What would the resolution be for this? Any help would be great thanx!
Looks like your code has the following issues, my be you copied from other possible acct trigger (my guess). Here are the problems why I am saying that
Please try the below code. I have fixed everthing, you can use code as is.
I hope this help
Was the solution helpful?