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
Haroon AhmadHaroon Ahmad 

SOQL Query with LIke criteria take too long

We're running into a performance issue that we would appreciate guidance on:
 
We need to a like query on the Name field in the Account object, something like:
 
[select name from account where name like '%bendoug%' or name like '%gustavo%' or name like '%Ben%' or name like '%wyeth%']
 
This query is taking very long time to process.
 
The business requirement is matching against the account name.
 
Has anybody run into this issue, and solved it?
 
Thanks.
 
-Haroon
Best Answer chosen by Admin (Salesforce Developers) 
blake.tanonblake.tanon

right, so if they are all of the same record type you could add that since it would be a common field amoung the accounts as well as an indexed one.

All Answers

blake.tanonblake.tanon

how many accounts do you have in the system?  If you have a lot, is there another field you can throw in there to trim the pool?

Haroon AhmadHaroon Ahmad

We have about 7 million.

 

Sorry, not sure what you mean by 'Trim the Pool'. Did you mean add a filter, so a smaller set of records get searched?

 

-Haroon

blake.tanonblake.tanon

right, so if they are all of the same record type you could add that since it would be a common field amoung the accounts as well as an indexed one.

This was selected as the best answer
Haroon AhmadHaroon Ahmad
Ok, let me exhaust that option.

But if the result set ends up having to stay pretty large, is there anything we can do in that case?
Bhawani SharmaBhawani Sharma
I think you can add some more filtered criteria like, you should look only the accounts modified in a time rage like in Last 6 months or in Last year AND some specific record type and some more additional criteria
sushant sussushant sus
hi,

Add some filter in query like last modydate less than or create date less than specfic date this wil reduce ur query record and query will be fast