0

I'm new to SOQL and apex world and I'm writing a dynamic SOQL query where I need to retrieve all the records that's firstname starts with eighter 'a' or 'A'. Using OR operator is not working.

Example -

Firststname__c   Lastname__c
Adam             Johnson
Amelia           Johnson
Johnson          Johnson

So, when I run the query it should return top two rows.

(Although I'm writing dynamic queries, I'm trying to run the query in the query editor first to make sure everything works as expected) Following are the queries I have tried: 1.

SELECT First_Name__c, Email__c, Last_Name__c FROM Student__c WHERE (Email__c LIKE 'A%' OR Email__c Like 'a%')

And it returns nothing.

2.

SELECT First_Name__c, Email__c, Last_Name__c FROM Student__c WHERE Email__c LIKE '[a-A]%'

Return nothing

3.

SELECT First_Name__c, Email__c, Last_Name__c FROM Student__c WHERE Email__c LIKE '[a-A]%' OR Email__c Like 'a%' OR Email__c Like 'a%'

It return records that's Email__c starts with 'a'.

3
  • 1
    Welcome to SSE! Can you edit the post and mention what soql query you have tried and what is the output for the same. Dec 15, 2022 at 12:48
  • @SaiPraveenKakkirala I have edited the post. Please take a look. Dec 15, 2022 at 13:10
  • Do you have any Records with Emails starting with A as you shared only FirstName starting with A Dec 15, 2022 at 13:17

1 Answer 1

1

soql queries are case insensitive so you don't need to use OR

this simple query will do your work

SELECT First_Name__c, Email__c, Last_Name__c FROM Student__c WHERE Email__c LIKE 'A%'

You must log in to answer this question.

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