Salesforce(apex) Query select with Where toLowerCa

2019-07-11 14:17发布

I using Salesforce (apex), I need to Query with a WHERE statement with toLowerCase ,i.e. I have a list (MyNames_list) with LowerCase values but the table values are not lowerCase.

In my Query when I check the Name in MyNames_list it will make toLowerCase value and then check it in the MyNames_list.

Something like this:

Name | LastName

BOBY | Testovich1

DANY | Testovich2

Ron  | Testovich3

and in my list:

MyNames_list :boby,dany,ron

That still will return me all rows, because WHERE statement will check it with LowerCase.

//only example (not working code)

for(Users user:[SELECT Name,LastName FROM Users 
                WHERE ( Name.toLowerCase() IN : MyNames_list) ] )
{  
    //code....
}  

Is there a way to do this in Salesforce (apex) Query ?

1条回答
Anthone
2楼-- · 2019-07-11 14:43

Salesforce is only case-sensitive for fields that are explicitly case-sensitive (ie an external id that has been marked as case-sensitive)

The field you are querying, Name is not case-sensitive - hence, you don't need to apply toLowerCase(). You will get all matching fields anyway.

So your query could be:

for(User u:[SELECT Name,LastName FROM User WHERE Name IN :MyNames_list)]){  
//code....
}  
查看更多
登录 后发表回答