Filtering by Long Text Area field in SOQL

  • I'm working on a custom search page, which will search through the fields of the Project object. I use dynamic SOQL query similar to that:

    String query = 'SELECT Name, Status__c ... 
        FROM Project__c WHERE Name LIKE \'%' + String.escapeSingleQuotes(name)
         +'%\' + ' OR Status__c = \'' + String.escapeSingleQuotes(status) +'\'';
    List<Project__c> projects = Database.query(query);
    

    But when I try to add to filter criteria Description__c field, which is Long Text Area, get the following error:

    System.QueryException: field 'Description__c' can not be filtered in query call

    How can I use Long Text Area fields in filtering of results?

    What values are in that field that you want to filter on ? Possible it shouldn't be a long text field, or you could optimize your data model and process by creating additional fields.

  • dino ursic

    dino ursic Correct answer

    8 years ago

    You can not use text area fields in SOQL and SOSL filter criterias.

    Try this approach:

    List<Project__c> projects = new List<Project__c>();
    for(Project__c proj : [SELECT Name, Status__c, Description__c FROM Project__c WHERE Name LIKE '%' + String.escapeSingleQuotes(name) +'%' + OR Status__c = String.escapeSingleQuotes(status)]) {
        if(proj.Description__c.contains('filter string')) {
            projects.add(proj);
        }
    }
    

License under CC-BY-SA with attribution


Content dated before 7/24/2021 11:53 AM