You need to sign in to do that
Don't have an account?
Amil Abdallah
Can't display results for whoid and whatid from Activity History
I have created a salesforce page which displays a datatable that is populated with an Account's activity history. I have created this table view as opposed to utilizing the related list view because the activity history gets very convoluted with email responses. The clients have requested a table view in which to filter out emails and other types of activities so that it's much more managable/easier to read.
In doing my research, I have come to find that the Activity History table is special and cannot be queried directly. Inconvenient as it is, I went ahead and created a soql query which joins the activity history to the account object as seen below:
[select id, name, ownerid,
(select id, subject, whoid, whatid, accountid, ownerid, activitydate, description, status, activitytype, istask, CreatedById from ActivityHistories WHERE not(subject like 'mass email%' OR subject like 'pardot list email%') ORDER BY activitydate DESC)
from account
where id = :ApexPages.currentPage().getParameters().get('id')]
The query works and I am able to display the data within the table with the exception of two fields, whoid ('name/contact' field) and whatid ('related to' field). When I run this query in the Force.com explorer I clearly see value for those fields populated in the results, however, when I query within the developer console, those fields return null. I am unable to display these fields in my table as they show up null in the result set. Does anyone know why I am unable to get these results within my apex code/visualforce page despite the fact that I can see the results in the force.com explorer? Any help is greatly appreciated.
In doing my research, I have come to find that the Activity History table is special and cannot be queried directly. Inconvenient as it is, I went ahead and created a soql query which joins the activity history to the account object as seen below:
[select id, name, ownerid,
(select id, subject, whoid, whatid, accountid, ownerid, activitydate, description, status, activitytype, istask, CreatedById from ActivityHistories WHERE not(subject like 'mass email%' OR subject like 'pardot list email%') ORDER BY activitydate DESC)
from account
where id = :ApexPages.currentPage().getParameters().get('id')]
The query works and I am able to display the data within the table with the exception of two fields, whoid ('name/contact' field) and whatid ('related to' field). When I run this query in the Force.com explorer I clearly see value for those fields populated in the results, however, when I query within the developer console, those fields return null. I am unable to display these fields in my table as they show up null in the result set. Does anyone know why I am unable to get these results within my apex code/visualforce page despite the fact that I can see the results in the force.com explorer? Any help is greatly appreciated.
All Answers
When you are checking the priview are you passing Id parmeter in URL ?
Like : https://Your_instance_Name/apex/YourVF_Page_Name?id='recordId'
what it will return ?
ApexPages.currentPage().getParameters().get('id')
Read all about it here: https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_activityhistory.htm