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
shashvatshashvat 

Accessing related field values from ActivityHistory

Hi

 

I m trying to execute the query below to extract values of fields - ActivityDate and Subject into a visualforce table :

 

SELECT(SELECT ActivityDate, Subject FROM ActivityHistories ORDER BY ActivityDate DESC LIMIT 1) FROM Case where Case.CaseNumber='00017011'

 

How to get the values of fields of inner queries to be displayed?

 

Is there any other work around as ActivityHistory is not query-able directly ?

 

My issues is that I have to construct a table that has some column values from SOQL queries Activity History, some values from Case object and values coming from an APi call to an external server. I m able to do the rest of the part but I m not still able to extract field values for ActivityHistory.

 

Please guide me with the same.

Santhosh KumarSanthosh Kumar
How to get the values of fields of inner queries to be displayed?

 Here is an example of reading the child records in Apex.

 

List<Case> cases = [SELECT(SELECT ActivityDate, Subject FROM ActivityHistories ORDER BY ActivityDate DESC LIMIT 1) FROM Case limit 10];

for (Case case1: cases) {
    if (case1.activityhistories.size() > 0) {
		System.debug(case1.activityhistories[0].ActivityDate);
	}
}