I have followed this official guide: SOQL Injection and came up with this:
String query = 'Select FirstName, LastName, Phone, Email From Contact Where ';
if(String.isNotBlank(fName)) {
firstName = '%'+fName+'%';
if(String.isNotBlank(lName)) {
lastName = '%'+lName+'%';
query += 'FirstName LIKE :firstName AND LastName LIKE :lastName';
} else {
query += 'FirstName LIKE :firstName';
}
} else {
if(String.isNotBlank(lName)) {
lastName = '%'+lName+'%';
query += 'LastName LIKE :lastName';
}
}
And this works perfect. But as I am performing a Contact search, I would like to have a perfect search result. So, I have replaced LIKE
with =
symbol. And then, my query is always of contactList.size() = 0
.
I am not sure what I am missing here. Can someone please shed some light here?