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
JSpenceJSpence 

SOQL Like/Regex Question

Is it possible to define a range to match in SOQL (like t-sql)?

 

For example Where not(name like 'P[0-9]%') ?

Rahul SharmaRahul Sharma

What shall be output of you example

JSpenceJSpence

Input:

p12345

p23455

p09865

PD121212

H9999

h4444

 

Expected output of my example

PD121212

H9999

h4444

 

Actual Output of my example:

p12345

p23455

p09865

PD121212

H9999

h4444

dkadordkador

SOQL supports the LIKE operator and allows for basic regex, but not something like this.  See the API docs for more info.

JSpenceJSpence

Weird. It will run it happily without any error messages but not return what I expect.

 

Thanks for the reply.

Rahul SharmaRahul Sharma

It will work, but just  not include record which starts with P[0-9].

for records like:   P[0-9]1223, P[0-9]556, etc, which ever starts with P[0-9]

 

Rich PRich P

This is an ugly hack, but it will accomplish your goal:

 

Where (not (name like 'P0%' or name like 'P1%' or  name like 'P2%' or name like 'P3%' or name like 'P4%' or name like 'P5%' or name like 'P6%' or name like 'P7%' or name like 'P8%' or name like 'P9%'))