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
lovetolearnlovetolearn 

Multiple Conditional Statements in SOQL Query

Hi, 

 

I am trying to create a SOQL with two AND conditons. It would look something similar to this: SELECT ID FROM Contact Where firstName ! = 'Test' AND lastName = 'User' AND Date_of_Birth__c != TODAY]. I know this syntax is not correct, but I am not sure what the correct syntax would be in this case. Please help. Thank you. 

 

TheIntegratorTheIntegrator

I cannot confirm the custom field, but there seems to be an error in firstName ! = 'Test'. There is a space between ! and =

 

 SELECT ID FROM Contact Where firstName != 'Test' AND lastName = 'User' AND Date_of_Birth__c != TODAY

lovetolearnlovetolearn

Hi, 

 

Thanks for your help. Thats actually a typo on my end. 

 

My biggest question is it possible to use two conditional statements in a SOQL query?

TheIntegratorTheIntegrator

Like the two ANDs you have in your query? Sure, its perfectly valid.

lovetolearnlovetolearn

Yep. Keeping getting a Save error though. 

TheIntegratorTheIntegrator

Could you paste your entire code along with the error you get on Save?

Noam DganiNoam Dgani

appart for the custom field mentioned ,which for all we know might not exist,

 

try - 

System.Today() instead of TODAY