0

I am trying to query the below query in my query editor. The below query is suppose to bring only one quote which is 'Q-100' but it returns me all the quotes that contains q-100. for example q-10001, q-10023...

My Query:

[ SELECT Quote_Nr__c,Web_Key__c, Approval_Status__c, Id, Presented_Date__c,Valid_Until__c 
  FROM SFDC_520_Quote__c 
  WHERE Quote_Nr__c  LIKE '%Q-100%']

Am I missing something in the query.

4
  • I don't understand. your query will return every quote that contains the string Q-100946 anywhere in it. If you want just one quote use the = sign instead of like, and avoid wildcards. Commented Nov 2, 2016 at 22:30
  • My bad it was suppose to be Q - 100 not Q - 100946
    – user31302
    Commented Nov 2, 2016 at 22:32
  • Yes, I tried using = but it doesn't work and returns me nothing.
    – user31302
    Commented Nov 2, 2016 at 22:34
  • Are you sure there is a record with exactly that name? Did you see my answer below? Commented Nov 2, 2016 at 22:34

1 Answer 1

4

Your query, as designed, will bring all quotes that contain the string Q-100. To use equality, your query should read

[ SELECT Quote_Nr__c,Web_Key__c, Approval_Status__c, Id, Presented_Date__c,Valid_Until__c 
  FROM SFDC_520_Quote__c 
  WHERE Quote_Nr__c = 'Q-100']

There is a big difference between equals and like.

=: Expression is true if the value in the specified fieldName equals the specified value in the expression. String comparisons using the equals operator are case-sensitive for unique case-sensitive fields and case-insensitive for all other fields.

LIKE: Expression is true if the value in the specified fieldName matches the characters of the text string in the specified value. The LIKE operator in SOQL and SOSL is similar to the LIKE operator in SQL; it provides a mechanism for matching partial text strings and includes support for wildcards. The % and _ wildcards are supported for the LIKE operator. The % wildcard matches zero or more characters. The _ wildcard matches exactly one character. The text string in the specified value must be enclosed in single quotes. The LIKE operator is supported for string fields only. The LIKE operator performs a case-insensitive match, unlike the case-sensitive matching in SQL. The LIKE operator in SOQL and SOSL supports escaping of special characters % or _. Don’t use the backslash character in a search except to escape a special character. For example, the following query matches Appleton, Apple, and Appl, but not Bappl SELECT AccountId, FirstName, lastname FROM Contact WHERE lastname LIKE 'appl%'

I recommend you read this article to familiarize yourself with the WHERE clause.

You must log in to answer this question.