What is a SOQL like query?

649    Asked by AlanTaylor in Salesforce , Asked on Sep 23, 2022

I am trying to make a query that will search for accounts with a name similar or exactly matching a field value.


So for example I have "Sales-Force" in the field. There is an account called "Salesforce" or "Sales Force"


My current query


Select Id, Name FROM Account WHERE Name LIKE '%Sales-Force%'
This isn't returning my accounts named "Sales Force" or "Salesforce" in my query editor.


UPDATED * My Apex code


string accountName= record.Name;
    if(accountName.contains('-'))
    {
        accountName = accountName.replace('-', '%');
    }
    if(accountName.contains(' '))
    {
        accountName = accountName.replace(' ', '%');
    }
    accountName= '%' + accountName+ '%';
List accountLookup = new List();
accountLookup = [Select Id, Name FROM Account WHERE Name LIKE :accountName];


Answered by Aditya Yadav

Your Answer

Interviews

Parent Categories