+ Start a Discussion
Jim MontgomeryJim Montgomery 

Error: Invalid field ActivityDate for SObject Account

I am trying to write a custom VF page to display account history only for the logged in user.
I am using account as the standard controller, and have an extension controller to do the filtering.
I am getting the above error when attempting to save my VF page.

Class:
public class AccExtensions{
      Public List<Account> AHS{get;set;}
            public AccExtensions(ApexPages.StandardController controller) {
          AHS=[select id, name,(select ActivityDate, ActivityType from ActivityHistories where OwnerId = :UserInfo.getUserId())from account where ID=:ApexPages.currentPage().getParameters().get('id')];
          for(Account ah:AHS) {
 
             
                AHS.add(ah);
}
}
}

VF Page

<apex:page standardController="Account" extensions="AccExtensions" >
<apex:pageBlock>
<apex:pageblockTable value="{!AHS}" var="acch">
<apex:Column headervalue = "Date" value="{!acch.ActivityDate}"/>
</apex:pageblockTable>
</apex:pageBlock>
</apex:page>
 
Best Answer chosen by Jim Montgomery
Jim MontgomeryJim Montgomery
This is what I ended up with. Controller: public class AccExtensions{ Public List AHS{get;set;} public AccExtensions(ApexPages.StandardController controller) { AHS=[select id, name,(select id,ActivityDate,short_notes__c,OwnerId, Owner.name,Activity_Type__c,description,subject from ActivityHistories order by activitydate DESC) from account where ID=:ApexPages.currentPage().getParameters().get('id')]; System.Debug('AHS: ' + AHS.get(0)); System.Debug('Activities: ' + AHS.get(0).ActivityHistories); } } VF Page:   

Jim Montgomery Manager, Sales Intelligence Operations Wolters Kluwer Tax & Accounting 20101 Hamilton Ave. Torrance, CA 90502 877-346-7148 jim.montgomery@wolterskluwer.com

All Answers

Rakesh51Rakesh51
You are retrieving value from Task record not account and hence field needs to be accessed from Task instead .
Jim MontgomeryJim Montgomery
Are you stating to replace ActivityHistories with task__r? Jim Montgomery Manager, Sales Intelligence Operations Wolters Kluwer Tax & Accounting 20101 Hamilton Ave. Torrance, CA 90502 877-346-7148 jim.montgomery@wolterskluwer.com
UC InnovationUC Innovation
Here's an example on how you can access the Activity History based on what you are trying to do:

Apex Controller:
 
public class AccExtensions {
	Public List<Account> AHS {get;set;}
    
    public AccExtensions(ApexPages.StandardController controller) {
    	AHS = [select id, name, (select ActivityDate, ActivityType from ActivityHistories where OwnerId = :UserInfo.getUserId()) from account where ID=:ApexPages.currentPage().getParameters().get('id')];
        
        System.Debug('AHS: ' + AHS.get(0));
        System.Debug('Activities: ' + AHS.get(0).ActivityHistories);
	}
}

Visualforce Page:
 
<apex:page standardController="Account" extensions="AccExtensions" >
	<apex:pageBlock>
        <apex:repeat value="{!AHS}" var="acct">
            <apex:pageblockTable value="{!acct.ActivityHistories}" var="activity">
                <apex:Column headervalue = "Date" value="{!activity.ActivityDate}"/>
            </apex:pageblockTable>
        </apex:repeat>
	</apex:pageBlock>
</apex:page>

Hope that helps!
 
UC InnovationUC Innovation
Jim, did the above work for you?
Jim MontgomeryJim Montgomery
This is what I ended up with. Controller: public class AccExtensions{ Public List AHS{get;set;} public AccExtensions(ApexPages.StandardController controller) { AHS=[select id, name,(select id,ActivityDate,short_notes__c,OwnerId, Owner.name,Activity_Type__c,description,subject from ActivityHistories order by activitydate DESC) from account where ID=:ApexPages.currentPage().getParameters().get('id')]; System.Debug('AHS: ' + AHS.get(0)); System.Debug('Activities: ' + AHS.get(0).ActivityHistories); } } VF Page:   

Jim Montgomery Manager, Sales Intelligence Operations Wolters Kluwer Tax & Accounting 20101 Hamilton Ave. Torrance, CA 90502 877-346-7148 jim.montgomery@wolterskluwer.com
This was selected as the best answer
UC InnovationUC Innovation
Glad that you were able to get it to work.