You need to sign in to do that
Don't have an account?
_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.
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
try this
where Description__c like '%Developer%'
That does not work.
Any way This works for me. Can you paste your code here?
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.
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.
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.
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.
Hi sfdcfox, SOSL is not possible. Just checked the documentation, it does not apply for long text area.
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
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.
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?