2

I have a SOSL search Query

String suppliedSearchText1  = 'account';
Set<String> setselectedObjects = new Set<String>{'Account','contact'};
String SearchQuery = 'FIND \'' + suppliedSearchText1 + '*, Success\' IN ALL  FIELDS RETURNING MP_Map_Point__c (id,AddressKey__c,Label__c, Entity__c,Status__c WHERE Status__c = \''+Helper_MPConstants.GEOCODE_SUCCESS+'\' AND Entity__c IN : setselectedObjects order by Id ASC limit 2000) ';
List<List<SObject>> listSoslSearchResult = Search.query(searchQuery);
List<MP_Map_Point__c> lstMapPoints = listSoslSearchResult[0];

here, I am searching for one string is'Account' in custom object is Mp_Map_Point__c but got getting the correct result as in data base.

First time it is returning 2000 record after than I am using id as a offset.. like..

 String SearchQuery = 'FIND \'' + suppliedSearchText1 + '*, Success\' IN ALL  FIELDS RETURNING MP_Map_Point__c (id,AddressKey__c,Label__c, Entity__c,Status__c  WHERE Status__c = \''+Helper_MPConstants.GEOCODE_SUCCESS+'\' AND Entity__c IN : setselectedObjects AND id > :offsetId order by Id ASC limit 2000) ';

the query will be like this

FIND {Account*, Success*} IN ALL FIELDS RETURNING MP_Map_Point__c (id,AddressKey__c,Label__c, Entity__c,Status__c,Latitude__c WHERE Entity__c IN ('Account','Contact') order by Id ASC ); 

here the search statement is :

find 'account' from mp_Map_Point__c where entity__c in (account,contact) and status__C = 'success' order by id.

but the result is not equal as the data in database. I don't know{str1,str2} how this works?

Or Is there any other way where I can Put the condition on search ... or multiple search ?

Thanks in advance!

  • 3
    How many total MP_Map_Point__c records are there? The first thing SOSL does is return the most relevant 2000 records, then applies your filter. It's quite possible to not have an expected result if the record falls outside the initial 200 records, regardless of filters as they get added AFTER the initial 2000. developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/… – Girbot Mar 21 '16 at 15:24
  • I have 9882 records in MP_Map_Point__c with status__c= 'Success' and entity__c = 'Account' and returning me the 4002 records in my application. – Shilpa Mar 22 '16 at 6:17
  • If you know what the fields you are searching for are why don't you use SOQL? This is assuming you question and exmaple represents the complexity of your requirement. You won't have the issue of the 2,000 limit before your filters are applied if SOQL is a viable alternative. – Girbot Mar 22 '16 at 9:47
  • No we don't know the search string,User can search for 'test' ,'Success','contact','USA' anything.... – Shilpa Mar 22 '16 at 13:18
  • That's not what I said - I said the fields you are searching in. – Girbot Mar 22 '16 at 13:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.