You need to sign in to do that
Don't have an account?
nwing
What EXACTLY does the 'LIKE' statement mean?
I have used this in a query on the Attachment Object as a filter for the Name field. I want it to filter in the following way.....
WHERE Name LIKE :CaseN AND Name LIKE 'ICB'
so it will pull anything with the Case Number and the string 'ICB' ANYWHERE in the Attachment Name.
As it seams to work I need to state the Name exactly to get any results...... which is no different then just using the ' = ' ......
Could anyone provide help on how to use the LIKE statement so it functions as a 'Contains' type of filter?
Thanks in advance....
if(caseN != null){ String filter1 = CaseN + '_ICB.xls'; //String filter2 = CaseN; CurrentDoc = [ SELECT Id, Name, ContentType, CreatedDate FROM Attachment WHERE Name LIKE :filter1 ];
You need to add wildcards to your strings:
WHERE Name LIKE '%CaseN%' AND Name LIKE '%ICB%'.
The Underscore is an operator in SOQL, so you'll want to be careful using that.
http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_soql_select_comparisonoperators.htm
ahh.... ! thanks big time for the link as well...... I was digging for that and just wasn't in the right spot....
oohh...... one issue though.... 'CaseN' is a variable. Any way to get that to work...... it doesn't appear to allow variables in a LIKE statement....... am I wrong?
try something like
I gave that a shot and the system did like the plus sign..... I will try again to be sure...... but I don't think it took.....
how inconvenient ...
then build your string first outside the query and use that as a variable. Something like
or, more specific to your code example, add the % to the filter1:
Oh, duh....... thanks.........
I did another way, but will print and post on my wall for future reminders......
Thanks for the help. Always encouraging to get someone in a discussion on things.....
How did you do it?
Oh, nothing fancy....... the way this is put together, I could just grab the parent id of the attachment directly...... probably a better way overall....... but I will definately be using the LIKE funcitonality more now that I have it in my head.
thanks again
Remember you can also build the entire query as a string, and then use database.query to query for that string...sometimes easier when you are building dynamic SOQL...