You need to sign in to do that
Don't have an account?
Greg Coogan
Error when querying with multiple conditions in the WHERE clause using AND
I am trying to run a query that has multiple conditions in the WHERE clause. If I reduce it to a single condition by removing two of the other conditions I need, the query works. I have three conditions and I have tried a query with each individual condition. They all work. However, when they are combined using AND, I receive an error. I have tried all different combinations of using parentheses to see if it makes a difference, but no luck. To provide an example, I have replaced the field names,object names, and values with fake names. I am using the developer console's query editor at this time.
Example:
SELECT SUM(CustomField1) FROM CustomObject__c WHERE CustomField1 = 'Value1' AND CustomField2 = 'Value2' AND CustomField3 != 'Value3'
I have referenced the SOQL documentation but no luck. Do you see anything wrong with my query?
Example:
SELECT SUM(CustomField1) FROM CustomObject__c WHERE CustomField1 = 'Value1' AND CustomField2 = 'Value2' AND CustomField3 != 'Value3'
I have referenced the SOQL documentation but no luck. Do you see anything wrong with my query?
All Answers
SELECT SUM(Amount) FROM Opportunity WHERE QuoteBillingFrequency__c = 'Monthly' AND Currency__c = 'USD' AND QuotePaymentMode__c != 'Credit Card'
Does it work with any combination of 2 fields?
1. Condition 1 and 2
2. Condition 1 and 3
3. Condition 2 and 3
However, if I open the console, try my original query, and get the error, then try the query with Condition 2 and 3, its also fails. They, if I copy that query from the top of the console when it originally worked, it works again. I am stunned. I checked and the queries appear identical.
I opened the two queries (both have Condition 2 and 3 but only one of them works) in Notepad++. In that application, when you double-click on a word, it will show you other instances of the word. Strangely, the "AND" operator and field name of Condition 3 do not highlight as expected. It appears as if they are one word. I think it is displaying the same on the front end, but the back-end encoding may be different. (Potentially different Unicode characters)
This is the strangest thing I've ever seen. Its hard to explain, but I did the best I could.