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
prady-cmprady-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

 

sfdcfoxsfdcfox

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.