You need to sign in to do that
Don't have an account?
Jim Montgomery
maximum trigger depth error
I have a trigger on task that will update the task with the accounts record type on insertion.
I also need to do this on an update, but get the "maximum Trigger Depth" error when adding before update to the trigger.
trigger TaskAccountType on Task (after insert) {
Task T = [select Id,WhatId,subject from task where Id = :trigger.new[0].Id];
if(trigger.new[0].Id!=null){
string WhatId = t.WhatId;
if(t.WhatId!=NULL){
if(WhatId.startswith('0')){
Account a = [select id,recordtypeid from Account where id =: trigger.new[0].AccountId];
if(trigger.new[0].AccountId!=null){
if(a.recordtypeid == '012i0000000Ou0CAAS'){
t.Account_record_Type__c ='Customer Account';
update T;
}
else
if(a.recordtypeid == '012i0000000Ou0EAAS'){
t.Account_record_Type__c = 'Prospect Account';
update T;
}
else
if(a.recordtypeid == '012i0000000Ou0DAAS'){
t.Account_record_Type__c = 'Partner Account';
update T;
}
}
}
}
}
}
I also need to do this on an update, but get the "maximum Trigger Depth" error when adding before update to the trigger.
trigger TaskAccountType on Task (after insert) {
Task T = [select Id,WhatId,subject from task where Id = :trigger.new[0].Id];
if(trigger.new[0].Id!=null){
string WhatId = t.WhatId;
if(t.WhatId!=NULL){
if(WhatId.startswith('0')){
Account a = [select id,recordtypeid from Account where id =: trigger.new[0].AccountId];
if(trigger.new[0].AccountId!=null){
if(a.recordtypeid == '012i0000000Ou0CAAS'){
t.Account_record_Type__c ='Customer Account';
update T;
}
else
if(a.recordtypeid == '012i0000000Ou0EAAS'){
t.Account_record_Type__c = 'Prospect Account';
update T;
}
else
if(a.recordtypeid == '012i0000000Ou0DAAS'){
t.Account_record_Type__c = 'Partner Account';
update T;
}
}
}
}
}
}
All Answers
trigger TaskAccountTypeContact on Task (before insert, before update) {
For (Task T : trigger.new){
string WhoID = t.WhoID;
if(t.WhoId!=NULL){
if(WhoID.startswith('0')){
if(T.AccountID!=NULL){
Account a = [select id,recordtypeid from Account where id =:T.AccountId];
if(a.recordtypeid == '012i0000000Ou0CAAS'){
t.Account_record_Type__c ='Customer Account';
}
else
if(a.recordtypeid == '012i0000000Ou0EAAS'){
t.Account_record_Type__c = 'Prospect Account';
}
else
if(a.recordtypeid == '012i0000000Ou0DAAS'){
t.Account_record_Type__c = 'Partner Account';
}
}
}
}
}
}