Reply
Contributor
MetaWhat
Posts: 5
0

Filter Empty Strings (Not Null) in SOQL.

Interesting behavior with SOQL query.

Here is the setup.

Some_Field__c is a Text length 20.

Some_Field__c is not null

This is proven by running

SELECT Some_Field__c FROM Account  WHERE Id ='0013000000Ik1srAAB'  and Some_Field__c !=null

and it returns the row.

And

SELECT Some_Field__c FROM Account  WHERE Id ='0013000000Ik1srAAB'  and Some_Field__c = null

does not return a row.

The row is an empty string but

SELECT Some_Field__c FROM Account  WHERE Id ='0013000000Ik1srAAB'  and Some_Field__c = ''

doesnt return anything.

Also,

SELECT Some_Field__c FROM Account  WHERE Id ='0013000000Ik1srAAB'  and Some_Field__c = '%'

doesn't return anything.


This is happening on a summer 08 sandbox org.

How do I filter on the empty string?

Visitor
devjdk470
Posts: 2
0

Re: Filter Empty Strings (Not Null) in SOQL.

I haven't tested it, but you should be able to use ',' to filter out nulls, similar to how it works in Salesforce filters:

http://ideas.salesforce.com/article/show/10093853
Contributor
jenneking
Posts: 3
0

Re: Filter Empty Strings (Not Null) in SOQL.

Try this...

 

FROM Account WHERE FieldName != null 

 

This works:  != null  

 

When i used the Add Condition in data loader, I tried Operation of "not equals" and a value of Null and it retuned:

 

     FROM Account WHERE AccountNumber != 'Null' 

 

The 'Null' is looking for a value of the work Null... so no good.

 

When i use the Add Condition in data loader, and try Operation of "not equals" and i leave the Value empty, it returns:

 

    FROM Account WHERE AccountNumber != '' 

 

The != '' works as well.

 

 

blog.ryansieve.com