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
_why the unlucky stiff_why the unlucky stiff 

SOQL Question - Syntax for keywords 'contains' and 'includes'

What would the syntax be for the following requirement in SOQL?

 

I have threee fields:

1. First Name

2. Last Name

3. Description (Long Text Area)

 

I need to get all names which have the word 'Developer' (or any keyword) in the 'Description' Long Text area. I have hit the wall trying to use the keywords 'contains' or 'includes' without success. Doesn anyone know how to build a SOQL using these both keywords?

 

Any help much appreciated.

Best Answer chosen by Admin (Salesforce Developers) 
sfdcfoxsfdcfox

You should use SOSL if possible. SOQL does not allow filtering on any type of field that contains more than 255 characters. However, the search indexer will index these fields and allow results to be available via the SOSL language.

All Answers

AshanAshan

try this

where Description__c like '%Developer%'

_why the unlucky stiff_why the unlucky stiff

That does not work.

AshanAshan

Any way This works for me. Can you paste your code here?

Sam27Sam27

Well as far as I can remember you can't filter or sort with "description" object, SOQL won't allow you to use "description" in 'where' condition or in 'order by'.

 

Maybe because it's a 'long text area', though m not sure. I once got stuck in the same position.

pankaj.raijadepankaj.raijade

Hi,

 

There is possible work arround for this.

 

you can have a trigger  before insert and update which will update a dummy boolean field = true if Description__c contains "developer" else false.

 

and you query the records on boolean field == true.

 

 

sfdcfoxsfdcfox

You should use SOSL if possible. SOQL does not allow filtering on any type of field that contains more than 255 characters. However, the search indexer will index these fields and allow results to be available via the SOSL language.

This was selected as the best answer
_why the unlucky stiff_why the unlucky stiff

Hi Guys, I think sfdcfox has the best answer, but I am still looking for  a solution. How would the SOSL query look like?

 

Ashan - The SOQL based on your suggestion would look like : SELECT fn__c, ln__c FROM CustomObj__c WHERE where Description__c like '%Developer%'

 

pankaj - That is not a option, already thought about that.

 

_why the unlucky stiff_why the unlucky stiff

Hi sfdcfox, SOSL is not possible. Just checked the documentation, it does not apply for long text area.

LakshmanLakshman

Hi,

I habe done long text area search using SOSL earlier as SOQL doesn't supports it.

For more information on SOSL click here.

 

Regards,

Lakshman

sfdcfoxsfdcfox

INCLUDES and EXCLUDES, by the way, is only for multi-select picklists (see the documentation). There is no "contains" keyword in SOQL; instead, you would use LIKE. But as we've already said, long text areas do not work in filters at all. You have to use SOSL to find text in long text area fields.

Apurva PadiyarApurva Padiyar
Hey, so I had a similar scenario and using SOQL query. In this query :
SELECT name, id,city FROM CustomObj__c WHERE where name like '%searchkey%'  

Say, if i need to add OR condition in WHERE how does the syntax look like?