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
Dean Rourk 2Dean Rourk 2 

Activity History

Can you guide me if I want to extract the field values of Activity history in your query, how would I do it?

I am trying to use this code but I don't understand how to write the wrapper

public ActivityHistory[] getHistory() {
       // List<Activities> act {get;set;}
       
        List<Account> AccountsWithActivityHistories = [ 
            // you can't query ActivityHistory directly; only in a subquery against another object type
            SELECT
            Id
            ,Name
            ,( SELECT ActivityDate, Description, whoid, whatid,Status, subject, istask, ActivityType
              FROM ActivityHistories)
            FROM Account WHERE Id = :accountId
        ];
       
        // ActivityHistories on Account
        for (Account a : AccountsWithActivityHistories) {
            for (ActivityHistory ah : a.getSObjects('ActivityHistories')) {
                              
                if (((string)ah.WhatId).startsWith('001')) {
                    // only add ActivityHistory's tied directly to an Account
                    activities.add(new ActivityWrapper(ah));
                   
                }
            }
        }       
       
    }