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
middha.vikram@gmail.commiddha.vikram@gmail.com 

SOSL Query

Hi,

 

Can anyone tell me that how to write a SOSL query for the query below ?

 

[select Id,Name frrom Asset where Name like '%abcd%']

 

I need to retreive all the Asset records whose name contains 'abcd'.

 

Regards

Vikram

Ankit AroraAnkit Arora

Try this :

 

List<List<SObject>> soslList = [FIND '*abcd*' IN NAME FIELDS RETURNING Asset (id, name)];

 

Thanks

Ankit Arora

 Blog | Facebook | Blog Page

middha.vikram@gmail.commiddha.vikram@gmail.com

Hi,

 

Thanks for the reply. I have been trying the same query but it does not seem to be working. the SOQL query and the SOSL given by you returns the different result.

 

It looks like FIND '*abcd*' is not same as '%abcd%'.

Please let me know if you have any thoughts on this.

 

Regards

Vikram

middha.vikram@gmail.commiddha.vikram@gmail.com

It looks like the limit of records fetched from SOSL is 200 only. :( 

Ankit AroraAnkit Arora

Yes, you can see the difference because only 200 records are returned via SOSL.

 

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

middha.vikram@gmail.commiddha.vikram@gmail.com

Yups. So this is of no use for me. I need to display all the records on the VF page. Can you suggest any other workaround for this ?

 

I have 3 Million Assets in the Sandbox and when I run this query [select Id from Asset where name like '%abcd%' where Name != null], It gives TIME OUT to me. 

 

Regards

Vikram

Ankit AroraAnkit Arora

Ideally there should be very few instance where you will get records more than 50000 when you are searching with some specific criteria. Otherwise there is no use of the search criteria.

 

So to avoid the time out issue you can just append limit to the query of 50000

 

[select Id from Asset where name like '%abcd%' where Name != null limit 50000]

 

And am hoping you are using "Name != null" to avoid non-selective query errors. Try as above suggested, let me know if you still face the problem.

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page