1

We have a field that contains "," (only the comma) in our Account object.

I am trying to run a extract query without success.

SELECT ID FROM ACCOUNT WHERE CUS_FIELD__C = ',' --No records returned...eventhough there are quite a number of records
SELECT ID FROM ACCOUNT WHERE CUS_FIELD__C = "," --Returns malformed query error
SELECT ID FROM ACCOUNT WHERE CUS_FIELD__C = '\,' --Malform error

Can someone tell me how to do extract those records where the field is "," (only the comma) ?

4
  • What type is this field? I tried the first form using a text field, seemed to work okay.
    – sfdcfox
    Commented Oct 22, 2015 at 1:59
  • This is a formula field
    – user25311
    Commented Oct 22, 2015 at 2:02
  • Are you sure the formula field value doesn't have any space before or after the comma? If no, your first query should work for a formula field. I just tried it in my dev Org.
    – Shruthi
    Commented Oct 23, 2015 at 0:21
  • Account a = [SELECT ID,Postal_Address__c FROM Account WHERE Id = 'xxx']; System.debug(a.Postal_address__c.length()); I choose an account which has just the comma in Postal_Address__c field and the length is returned as 1 as shown above
    – user25311
    Commented Oct 23, 2015 at 3:45

1 Answer 1

0

This should work:

SELECT ID FROM ACCOUNT WHERE CUS_FIELD__C like '%,%'

Use Like clause in SOQL: https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_sosl_where.htm

1
  • 1
    That would not work...because the SOQL query that you have mentioned will return all records where "," (comma) is present..I believe the user is asking for a way to pull all the records where the ONLY data is just the comma
    – user25311
    Commented Oct 22, 2015 at 22:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .