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 

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';        
	}
	}
}
}