Find your content:

Search form

You are here

When does an activity get logged in openactivities or ActivityHistory?

 
Share

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?


Attribution to: Prady

Possible Suggestion/Solution #1

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:

System.debug(acc[0].OpenActivities);
System.debug(acc[0].ActivityHistories);

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


Attribution to: eyescream
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/5078

My Block Status

My Block Content