You need to sign in to do that
Don't have an account?
Allison Humphrey 7
Help - I've messed up a Trigger and it's not working now - Pretty sure it has to do with the catch exception at the end, but I can't figure it out.
I was adding in an additional section & I think I messed up the ending with the Catch exception. It was working fine before I added in the section for Creative BQA & not it's not firing for any of the items. I think I erased some part of the catch exception & didn't get it correct. I was able to get it to where it would save, but it doesn't seem to be firing to make the changes requested.
ANY help would be greatly appreciated.
Thanks!
Here is my code:
trigger TaskTrigger on Task (before insert) {
try{
boolean active = [Select Active__c from TriggerOptions__c where Name = 'DisplayTaskTrigger' limit 1].Active__c;
if(active==true){
for(Task t:Trigger.New){
try{
// if Subject = "AO - Advertiser Tagging & QA" then recordtype is "Ad Tag & QA"
ID adTagQATypeID = Schema.SObjectType.Task.getRecordTypeInfosByName().get('Ad Tag & QA').getRecordTypeId();
if(t.Subject=='AO - Advertiser Tagging & QA'){
t.RecordTypeId=adTagQATypeID;
if(Schema.SObjectType.Task.isUpdateable()){
update t;
}
}
// if Subject = "AO - Technical QA " then recordtype is "Technical QA"
ID technicalQATypeID = Schema.SObjectType.Task.getRecordTypeInfosByName().get('Technical QA').getRecordTypeId();
if(t.Subject=='AO - Technical QA'){
t.RecordTypeId=technicalQATypeID;
if(Schema.SObjectType.Task.isUpdateable()){
update t;
}
}
// if Subject = "AO - Setup Network Pixels" then recordtype is "Pixel Setup"
ID pixelSetupTypeID = Schema.SObjectType.Task.getRecordTypeInfosByName().get('Pixel Setup').getRecordTypeId();
if(t.Subject=='AO - Setup Network Pixels'){
t.RecordTypeId=pixelSetupTypeID;
if(Schema.SObjectType.Task.isUpdateable()){
update t;
}
}
// if Subject = "AM - Creative BQA" then recordtype is "Creative BQA"
ID creativeBQATypeID = Schema.SObjectType.Task.getRecordTypeInfosByName().get('Creative BQA').getRecordTypeId();
if(t.Subject=='AM - Creative BQA'){
t.RecordTypeId=creativeBQATypeID;
if(Schema.SObjectType.Task.isUpdateable()){
update t;
}
}
} catch(Exception e){
system.debug(e);}
}
}
} catch(Exception e){
system.debug(e);}
}
ANY help would be greatly appreciated.
Thanks!
Here is my code:
trigger TaskTrigger on Task (before insert) {
try{
boolean active = [Select Active__c from TriggerOptions__c where Name = 'DisplayTaskTrigger' limit 1].Active__c;
if(active==true){
for(Task t:Trigger.New){
try{
// if Subject = "AO - Advertiser Tagging & QA" then recordtype is "Ad Tag & QA"
ID adTagQATypeID = Schema.SObjectType.Task.getRecordTypeInfosByName().get('Ad Tag & QA').getRecordTypeId();
if(t.Subject=='AO - Advertiser Tagging & QA'){
t.RecordTypeId=adTagQATypeID;
if(Schema.SObjectType.Task.isUpdateable()){
update t;
}
}
// if Subject = "AO - Technical QA " then recordtype is "Technical QA"
ID technicalQATypeID = Schema.SObjectType.Task.getRecordTypeInfosByName().get('Technical QA').getRecordTypeId();
if(t.Subject=='AO - Technical QA'){
t.RecordTypeId=technicalQATypeID;
if(Schema.SObjectType.Task.isUpdateable()){
update t;
}
}
// if Subject = "AO - Setup Network Pixels" then recordtype is "Pixel Setup"
ID pixelSetupTypeID = Schema.SObjectType.Task.getRecordTypeInfosByName().get('Pixel Setup').getRecordTypeId();
if(t.Subject=='AO - Setup Network Pixels'){
t.RecordTypeId=pixelSetupTypeID;
if(Schema.SObjectType.Task.isUpdateable()){
update t;
}
}
// if Subject = "AM - Creative BQA" then recordtype is "Creative BQA"
ID creativeBQATypeID = Schema.SObjectType.Task.getRecordTypeInfosByName().get('Creative BQA').getRecordTypeId();
if(t.Subject=='AM - Creative BQA'){
t.RecordTypeId=creativeBQATypeID;
if(Schema.SObjectType.Task.isUpdateable()){
update t;
}
}
} catch(Exception e){
system.debug(e);}
}
}
} catch(Exception e){
system.debug(e);}
}
Please remove all the update statements from the trigger. your trigger should work.You do not need update statements in the trigger as your trigger is a "before insert" trigger and DML statements in the loop is a bad idea.
I have changed the trigger a bit. Hope this is what you are looking for
All Answers
Please remove all the update statements from the trigger. your trigger should work.You do not need update statements in the trigger as your trigger is a "before insert" trigger and DML statements in the loop is a bad idea.
I have changed the trigger a bit. Hope this is what you are looking for