I'm having trouble getting my test class to pass tests. Getting:
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, UpdateAccountActivityDescription: execution of AfterUpdate caused by: System.QueryException: List has no rows for assignment to SObject Trigger.UpdateAccountActivityDescription: line 6, column 1: []
as an error.
Trigger
trigger UpdateAccountActivityDescription on Task (after insert,after update) {
if(Trigger.isAfter) {
if(Trigger.isUpdate){
for(Task t : Trigger.new) {
// We need to update associated Opportunity Fields with Fields from Case.
Account acc = [SELECT Id, Recent_Activity_Notes__c, Recent_Activity_Date__c, Recent_Activity_Owner__c From Account WHERE Id = :t.WhoId ];
acc.Recent_Activity_Notes__c = t.Description;
acc.Recent_Activity_Date__c = t.CreatedDate;
acc.Recent_Activity_Owner__c = t.WhoId;
update acc;
}
}
}
}
Test Class
@isTest
public class UpdateAccountActivityDecscription_Test {
static testMethod void CreateAccountTask(){
Account acc = new Account();
acc.Name = 'Test Account';
insert acc;
}
static testMethod void CreateTask(){
Account acc1 = new Account();
acc1.Name = 'Test Account1';
acc1.Recent_Activity_Notes__c = 'Test Version one';
acc1.Recent_Activity_Date__c = date.parse('12/12/2013');
insert acc1;
Profile p = [SELECT Id FROM Profile WHERE Name = 'Standard User'];
User u1 = new User(Alias = 'testa', Email ='[email protected]', EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US', LocaleSidKey='en_US', ProfileId= p.Id,
TimeZoneSidKey= 'America/Los_Angeles', UserName= '[email protected]');
System.runAs(u1) {
Task t1 = New Task();
t1.Subject = 'Task1 New';
t1.Description = 'Update Task1 Name';
t1.WhatId = acc1.id;
insert t1;
t1.Description = 'New New New Task1';
update t1;
}
}
}