function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Jim MontgomeryJim Montgomery 

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';               
        }
}
}
}
}
}
Marcilio SouzaMarcilio Souza
Hi check your executation log maybe some field is not filled.

 
VamsiVamsi
Hi Jim,

Replace T.AccountID with T.WhatID from the below 

 if(T.AccountID!=NULL){
    Account a = [select id,recordtypeid from Account where id =:T.AccountId];