+ Start a Discussion
tengeltengel 

ActivityHistory does not support query

Hi all, apex n00b here...

 

I am trying to modify this lovely VF example from Jeff Doyglas (http://blog.jeffdouglas.com/2009/05/08/inline-visualforce-pages-with-standard-page-layouts/) to enable Activity History searching for my users. Everything goes great until actually attempting to search, where I receive this error:

 

System.QueryException: entity type ActivityHistory does not support query 

Class.ActivitySearchController.search: line 39, column 1

 

Can anyone offer a suggestion for modifying the class below to make this work? I know that ActivityHistory querying requires a relationship query, but I am not sure how to achieve this in the following scenario:

 

public class ActivitySearchController {
 
    //added an instance varaible for the standard controller
    private ApexPages.StandardController controller {get; set;}
    // the actual account
    private Account a;
    // the results from the search. do not init the results or a blank rows show up initially on page load
    public List<ActivityHistory> searchResults {get;set;}
 
    // the text in the search box
    public string searchText {
        get {
            if (searchText == null) searchText = 'Enter keywords'; // prefill the search box for ease of use
            return searchText;
        }
        set;
    }
 
    public ActivitySearchController(ApexPages.StandardController controller) {
 
        //initialize the stanrdard controller
        this.controller = controller;
        this.a = (Account)controller.getRecord();
 
    }
 
    // fired when the search button is clicked
    public PageReference search() {
        if (searchResults == null) {
            searchResults = new List<ActivityHistory>(); // init the list if it is null
        } else {
            searchResults.clear(); // clear out the current results if they exist
        }
        // Note: you could have achieved the same results as above by just using:
        // searchResults = new List<categoryWrapper>();
     
        // use some dynamic soql to find the related activities by subject
        String qry = 'Select ah.Id, ah.subject, ah.whoid, ah.whatid, ah.accountid, ah.ownerid, ah.activitydate, ah.description from ActivityHistory ah Where AccountId = \''+a.Id+'\' And ah.Subject LIKE \'%'+searchText+'%\' Order By ah.Subject';
        searchResults = Database.query(qry);
        return null;
    }
 
}

 

RajivRajiv

Use this query: 

 

String qry = 'Select(Select Id, subject, whoid, whatid, accountid, ownerid, activitydate, description from ActivityHistories where Subject LIKE \'%'+searchText+'%\' Order By Subject') FROM Account  where Id = \''+ a.Id+'\'';

tengeltengel

Thanks, Rajiv. I gave that a shot, but now receive the following error:

 

Error: Compile Error: line 38:217 no viable alternative at character '\' at line 38 column 217

 

Any idea why that is happening?

RajivRajiv

 use this query

 

String qry = 'Select Id,(Select Id, subject, whoid, whatid, accountid, ownerid, activitydate, description from ActivityHistories where Subject LIKE \'%'+searchText+'%\' Order By Subject) FROM Account  where Id = a.Id';