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
vijaymindvijaymind 

How make Filter Criteria on TextArea in SOQL And SOSL

I just want make a like query on text area type field. How can do it ? 

Please give me some idea.

 

 

Thanks

 

Best Answer chosen by Admin (Salesforce Developers) 
Prafull G.Prafull G.

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

Alternative is to fetch all records and then iterate (using for loop) to check your filter criteria.

 

Something like You have a field textarea__c on Account of type textarea and you want to fetch only accounts having value as "developer test" in field textarea__c.

 

The query SELECT Id, Name FROM Account where textarea__c like '%developer test%' will not work and you can not use this field in where clause.

 

Alternative way

List<Account> filteredaccounts = new List<Account>();

for(Account act : [select id, name, textarea__c from Account) {

    if(act.textarea__c.contains('developer test')) {

        filteredaccounts.add(act);

    }

}

 

We have some other String methods like.. startswith, indexof which can be used to filter.

 

Let me know if this helps.

 

Regards,

All Answers

Prafull G.Prafull G.

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

Alternative is to fetch all records and then iterate (using for loop) to check your filter criteria.

 

Something like You have a field textarea__c on Account of type textarea and you want to fetch only accounts having value as "developer test" in field textarea__c.

 

The query SELECT Id, Name FROM Account where textarea__c like '%developer test%' will not work and you can not use this field in where clause.

 

Alternative way

List<Account> filteredaccounts = new List<Account>();

for(Account act : [select id, name, textarea__c from Account) {

    if(act.textarea__c.contains('developer test')) {

        filteredaccounts.add(act);

    }

}

 

We have some other String methods like.. startswith, indexof which can be used to filter.

 

Let me know if this helps.

 

Regards,

This was selected as the best answer
vijaymindvijaymind

Thanks crmtech21,

 

But I have millions of records, can not proceed in this way.

 

tggagnetggagne
Is there even a way to see if textarea fields are null or not null?

Here's what striking out looks like.

force query "select casenumber, id from case where feature_data__c != null"
casenumber, id from case where feature_data__c != null
                               ^
ERROR at Row:1:Column:39
field 'feature_data__c' can not be filtered in query call
Arpit Mantri 13Arpit Mantri 13
Hi Tggagne,

If your functionality can not live without this feature then there is a workaround that you can create a checkbox and update it using workflow field update on change of feature_Data__c change. So in workflow just check below:

criteria :
IsChanged(feature_Data__c) && len(feature_Data__c) >0 

Workflow action : field update :
Checkbox = true

Now you can use this checkbox in your query.

Happy coding and designing systems..
Amit Dhawan 32Amit Dhawan 32
select name, TextArea_Search__c from account
where TextArea_Search__c like '%missing%'
Amit Dhawan 32Amit Dhawan 32
The TextArea  field can be used in SOQL , that is the correct answer. I have made the field and tested it out