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
Mark CrooksMark Crooks 

Is it possible to search for an exact match only?

Hi, Could anyone tell me whether this is possible?
I'm wanting to check whether an account name already exists within my SF database.
Let's say I have an existing account named "Test Computers", when I submit a search for 'Test' only I DON'T want Test Computers to be included in the results.

"FIND {"Test"} IN Name FIELDS RETURNING account (account.Id)"

Thanks,

Mark
Best Answer chosen by Mark Crooks
Vikash TiwaryVikash Tiwary
Mark,

SOSL matches fields based on a word match while SOQL performs an exact match by default (when not using wildcards). For example, searching for 'Digital' in SOSL returns records whose field values are 'Digital' or 'The Digital Company', but SOQL returns only records with field values of 'Digital'.

However, workaround that you may take is that let SOSL return all the results then iterate over those results and compare the value that you search against particular field. If match found store in separate list. I am not sure how much this works for your scenario but please do let me know if it works.

Thanks

All Answers

Vikash TiwaryVikash Tiwary
Mark,

SOSL matches fields based on a word match while SOQL performs an exact match by default (when not using wildcards). For example, searching for 'Digital' in SOSL returns records whose field values are 'Digital' or 'The Digital Company', but SOQL returns only records with field values of 'Digital'.

However, workaround that you may take is that let SOSL return all the results then iterate over those results and compare the value that you search against particular field. If match found store in separate list. I am not sure how much this works for your scenario but please do let me know if it works.

Thanks
This was selected as the best answer
Himanshu ParasharHimanshu Parashar
Hi Mark,

what if you run SOQL instead of SOSL ?
 
select id,name from Account where name ='Test' limit 10

Thanks,
Himanshu
Salesforce Certified Developer | Administrator | Service Cloud Consultant

P.S. If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer.
 
Mark CrooksMark Crooks
Thank you both for replying. Looks like comparing the results to my search term will do the trick.