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
GailGail 

Cannot filter using String.contains

the Apex class:

public with sharing class AcctActivityList{
  
    public Account acct {get; set;}
    public List<ActivityHistory> ClosedTasks {get; set;}
    string mail = 'mail';
  
    public AcctActivityList(ApexPages.StandardController stdcontroller) {
        //get account
        acct = (Account)stdController.getRecord();
        //get activity history - can't query activity history directly, just in a subquery against another object

        SObject[] ActivityHistory = [Select id, (select Id, AccountId, Account.Name, ActivityDate, ActivityType, Description, OwnerId, Subject,
                                        LastModifiedDate, IsTask, WhatId, WhoId from ActivityHistories where
                                        (ActivityType !='Email' or Subject.contains('email')) ORDER by ActivityDate DESC)
                           from Account where Id =: acct.id];
      
        ClosedTasks = (List<ActivityHistory>)ActivityHistory.get(0).getSObjects('ActivityHistories');
      
    }
}


Why is my string.contains filter not working (i.e. why can't I save the code)?
When I try to save, I get the error: unexpected token: 'email'. The same is true if the filter is Subject.contains('email') == false.

I've seen this string class referenced various places around the web and it's still not working. I also tried reverting to API 27 (it was on 29) in case there was a bug in that API. No go.
Vidya DVidya D
contains is applicable to String and is not part of Comparison Operators.  Change to LIKE operator should solve

SObject[] ActivityHistory = [Select id, (select Id, AccountId, Account.Name, ActivityDate, ActivityType, Description, OwnerId, Subject,
                                        LastModifiedDate, IsTask, WhatId, WhoId from ActivityHistories where
                                        (ActivityType !='Email' or Subject like  '%email%') ORDER by ActivityDate DESC)
                           from Account where Id =: acct.id];

http://www.salesforce.com/us/developer/docs/dbcom_soql_sosl/Content/sforce_api_calls_soql_select_comparisonoperators.htm

GailGail
Thanks so much, that answers my question but begets another question. What I really need to query is that subject is NOT like %email%. I've been looking in your link and in general searches and trying variations of using NOT() and !() and I can't seem to get it to work.