You need to sign in to do that
Don't have an account?
prady-cm
activities not getting logged in openactivities or ActivityHistory in Test class
Hi,
I am assiging a task to an account. When i query the account i cant see the assigned task in openactivities or Activityhistories. Any idea this doesnt come in
static testMethod void AccountWithOpenTask() { Account a = new Account(name ='Test Account'); insert a; Task t = new task(); t.Whatid = a.id; t.Subject = 'Call'; t.Status = 'In Progress'; t.Priority = 'Normal'; insert t; Task tk = [SELECT Id, LastModifiedDate,whatID,What.name FROM Task WHERE Id = : t.Id]; system.debug('Task is '+ tk); List<Account> acc= [SELECT Id, Name, (SELECT Id, Subject,CreatedDate,LastModifiedDate FROM OpenActivities WHERE (NOT Subject LIKE '%Mass Email%') ORDER BY LastModifiedDate DESC LIMIT 1 ), (SELECT Id, Subject,CreatedDate,LastModifiedDate FROM ActivityHistories WHERE (NOT Subject LIKE '%Mass Email%') ORDER BY LastModifiedDate DESC LIMIT 1 ) FROM Account ]; System.debug('acc in Test class ' + acc);//returns name and ID System.debug('OpenActivities in Test class ' + acc[0].OpenActivities);// these return nothing System.debug('ActivityHistories in Test class ' + acc[0].ActivityHistories);// these return nothing
Are you using @isTest(SeeAllData=true)? If so, you might not be querying the account you think you are. Alter "FROM Account" to read "FROM Account WHERE Id = :a.id" and see if that changes your results.