1

I am using SOSL query:

List<List<Account>> acclist = [FIND :newstring IN ALL FIELDS RETURNING Account(id,Name,FirstName,LastName,Territory_vod__c,NPI_vod__c where RecordType.Name='Prescriber' ) ];

newString is set and consists of names. So,if there are 3 account with name test then it will retrieve all those accounts.

I want to retrieve only one account record for each value in newString.

Is it possible to retrieve only the first record for each name that is matching with account name in SOSL query itself(by using something like LIMIT).I need it in SOSL query itself.

6
  • you could use Limit. Something like List<List<Account>> acclist = [FIND :newstring IN ALL FIELDS RETURNING Account(id,Name,FirstName,LastName,Territory_vod__c,NPI_vod__c where RecordType.Name='Prescriber' LIMIT 1 ) ]; but that will return only one record.
    – Mahmood
    Mar 7, 2017 at 7:49
  • But if newString is having five names and there is a account for first name itself,then it will not check for other 4 values in newString. Let me know if I am wrong on this.
    – devsfdc
    Mar 7, 2017 at 7:52
  • No, you are right, and that what I wrote in my earlier comment. So, I got your requirements clearly now. Let me think over it. :)
    – Mahmood
    Mar 7, 2017 at 7:55
  • As @Mahmood said,you can use LIMIT clause and as per your question you want to return only one record using SOSL , so that should meet your requirement.If you want something else, please update your question.
    – Samir
    Mar 7, 2017 at 7:55
  • It is no possible with a single query. You can do something with aggregate queries, but you would need to do some additional processing.
    – Raul
    Mar 7, 2017 at 8:00

0

You must log in to answer this question.

Browse other questions tagged .