You need to sign in to do that
Don't have an account?
sfdc integrator.ax1790
Regular Expression in SOQL
Hi,
I need to query records[soql] which starts with non-alphabet characters.
Please help me.
Suresh S
function readOnly(count){ }
You need to sign in to do that
Don't have an account?
Hi,
I need to query records[soql] which starts with non-alphabet characters.
Please help me.
Suresh S
That's a clever idea. I did not consider modifying the object to make the task easier. Good job! -Glyn
All Answers
Hi..
Hope this will help :
http://www.salesforcegeneral.com/salesforce-articles/regular-expressions-in-apex-code.html
Please accept my answer as a solution if my solution was helpful. This will make it available to others as a proper answer. If you felt that I went above and beyond please give me Kudos by clicking on on the star icon.
Thanks,
Cool Sfdc
Suresh,
Unfortunately, SOQL does not support regular expressions. But you can do a long WHERE clause:
SELECT Id, Name FROM sObject
WHERE Name NOT LIKE 'A%' AND Name NOT LIKE 'B%' AND Name NOT LIKE 'C%' AND ... AND Name NOT LIKE 'Z%'
Since SOQL compares in a case-insensitive manner, you only need 26 'NOT LIKE' comparisons, not 52.
If this helps, please mark it as a solution, and give kudos (click on the star) if you think I deserve them. Thanks!
-Glyn Anderson
Certified Salesforce Developer | Certified Salesforce Administrator
Suresh,
Try something like this:
If this helps, please mark it as a solution, and give kudos (click on the star) if you think I deserve them. Thanks!
-Glyn Anderson
Certified Salesforce Developer | Certified Salesforce Administrator
Thanks GlynA,
Is there any better approach other than this.
Suresh S
Well, I've done more research and even this approach won't work because you can't do "NOT LIKE", you can only do "LIKE".
If you know what non-alphabetic characters the record names will start with, you can set up a big where clause (modify my code to do so):
WHERE Name LIKE '1%' OR Name LIKE '2%' OR...
I've tested this with a large number of terms in the expression (roughly 60 or so) and had no problem. It's ugly, but it works.
-Glyn
Thanks GlynA,
The issue has been resolved. I have gone with custom formula Field. It worked fine.
Thanks for your hard work.
As you told that if we know the non-alphabetic character then it is fine. But we are getting the values dynamically. So i cannot change the code each time when a new special character has added(!@#$%^&*()<>:?"{}|[]\_-+=-/*`~;'0123456789)
Suresh S
That's a clever idea. I did not consider modifying the object to make the task easier. Good job! -Glyn