+ Start a Discussion
Jim MontgomeryJim Montgomery 

list has no rows for assignment task trigger

I am trying to add a field from the account when creating a task on an opportunity or account, or contact. I should be able to access the AccountId field on the task record to pull this,.

trigger AccountRecordType on Task (before insert, before update) {
for (Task T : trigger.New){
Account a = [select id,recordtypeid from Account where id =: trigger.new[0].AccountId];    
if(a.recordtypeid == '012i0000000Ou0CAAS'){
        t.Account_record_Type__c = 'Customer Account';        
        }
        if(a.recordtypeid == '012i0000000Ou0EAAS'){
        t.Account_record_Type__c = 'Prospect Account';        
        }
        if(a.recordtypeid == '012i0000000Ou0DAAS'){
        t.Account_record_Type__c = 'Partner Account Account';        
        }
}
}
Best Answer chosen by Jim Montgomery
Raj VakatiRaj Vakati
trigger AccountRecordType on Task (before insert, before update) {
for (Task T : trigger.New){
	if(trigger.new[0].AccountId!=null){
Account a = [select id,recordtypeid from Account where id =: trigger.new[0].AccountId];    
if(a.recordtypeid == '012i0000000Ou0CAAS'){
	t.Account_record_Type__c = 'Customer Account';        
	}
	if(a.recordtypeid == '012i0000000Ou0EAAS'){
	t.Account_record_Type__c = 'Prospect Account';        
	}
	if(a.recordtypeid == '012i0000000Ou0DAAS'){
	t.Account_record_Type__c = 'Partner Account Account';        
	}
	}
}
}