In Test class I am trying to create an event and see this event is getting logged in Open Activities or Activity History

Account a = new Account(name ='Test Account');
    insert a;

    Task t = new task();        
    t.Whatid = a.id;

    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 WHERE Id =: a.Id];
    System.debug('acc in Test class ' + acc);
    // This results in USER_DEBUG|[56]|DEBUG|acc in Test class (Account:{Name=Test Account, Id=001W0000008D6QjIAK}) 

Any idea why the Task doesn't show up in the debug statement?

  • It shows up in ActivityHistory only when the status is Completed. In Progress should show up in Open Activities. Try setting a due date and the status. – techtrekker Dec 5 '12 at 8:28

Subqueries ("going down") don't show up in the debug log, most likely because it would make it grow too big.

Most of the time it's same with "going up" - add Owner.Name, Owner.Manager.Profile.Name to the query and debug will probably show only the OwnerId.

So simply add these 2 guys explicitly in the code:


As to which related list is the correct one - go to Setup -> Customize -> Activities -> Task fields -> Status and examine the "Closed" column in picklist values.

Task.Status picklist values


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.