Find your content:

Search form

You are here

Field can not be filtered in SOQL query call

 
Share

Here is my SOQL code for finding records to update but it is generating a compiler error like "field 'Chatter_Monitor_Policy_Keyword__c' can not be filtered in query call". Why can't I filter by this field?

string abc = obj[0].Chatter_Monitor_Policy_Keyword__c;
string s ='%'+ abc + '%'; 
List<Chatter_Monitor_Policy__c> records = [SELECT Id, Chatter_Monitor_Policy_Keyword__c from Chatter_Monitor_Policy__c where Chatter_Monitor_Policy_Keyword__c Like:s and CreatedById =: UserInfo.getUserId()];
if(records.size()!=null)
{
  for(Integer i=0; i<records.size(); i++)
  {
    records[0].Chatter_Monitor_Policy_Keyword__c = s;
    update records[0];
  }
}

Attribution to: Kishan Trambadiya

Possible Suggestion/Solution #1

If Chatter_Monitor_Policy_Keyword__c is a text area then you can't filter by it, though if it truly is a keyword (or short list of keywords) then it should just be a text field which you will be able to filter by.

Can you confirm what type of field you are using? If it is a text area then I'd suggest changing it to a text field if possible.

If you absolutely can't change the field type, then you're probably limited to selecting all of the records and performing the search in code — to do this you'll likely need to leverage a batch apex class to process the data volumes involved.


Attribution to: Matt Lacey

Possible Suggestion/Solution #2

As indicated in the attached screenshot, check the "filterable" acces property of field in schema browser (Force.com IDE etc). This property indicates whether the field is filterable (true) or not (false). If true, then this field can be specified in the WHERE clause of a query string in a query() call. More details here : http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_describesobjects_describesobjectresult.htm

Check the "filterable" acces property of field in schema browser


Attribution to: Abhinav Gupta

Possible Suggestion/Solution #3

Textarea field types are filterable, but it needs to be done in the QueryResult

Quote from SOAP API page

Textarea Field Type

Textarea fields contain text that can be longer than 4000 bytes. Unlike string fields, textarea fields cannot be specified in the WHERE clause of a queryString of a query() call. To filter records on this field, you must do so while processing records in the QueryResult. For fields with this restriction, its filterable field in the Field type (described in the fields property of the DescribeSObjectResult) is false.

So get the query results into a queryresult object, and filter over each of the returned objects.


Attribution to: Saariko
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/1332

My Block Status

My Block Content