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

Trigger to add account data to task not firing on insert, but fires on update.
Works on update, but not o insert
Works fine on update, but not on insert. Record Type is not stamped on the activity.
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';
}
}
}
}
}
}
Works fine on update, but not on insert. Record Type is not stamped on the activity.
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';
}
}
}
}
}
}
Replace T.AccountID with T.WhatID from the below
if(T.AccountID!=NULL){
Account a = [select id,recordtypeid from Account where id =:T.AccountId];