3

Hello!

I have a lookup component that uses a dynamic query based around FIND. It works great except when querying Standard Profiles. If I search for profiles, only custom profiles are returned.

Example: I start typing System, expecting to see System Administrator returned but it is not present in the results.

FIND {syste*} IN Name FIELDS RETURNING Profile(Name, Id)

As a test I am running SELECT Name, Id FROM Profile WHERE Name = 'System Administrator' in the same code block which is successfully returning the System Admin Standard profile.

Any ideas why the first query will only return Custom Profiles and not Standard ones?

Thank you.

3
  • I see the same on the scratch org I tested with. I'm gonna suggest that's because Salesforce has forgotten to ensure that standard profiles get indexed, but perhaps someone else knows for sure. Note, too, that SOSL is for searching for SObject records, so I'm quite surprised it works for even custom Profiles (which are setup data, not records).
    – Phil W
    Oct 31, 2023 at 16:34
  • @PhilW Remember the old PTn profile names? Those are the values that are still indexed....
    – sfdcfox
    Oct 31, 2023 at 20:11
  • 1
    D'oh! That's before my time... and such a weird inconsistency to still have!
    – Phil W
    Oct 31, 2023 at 21:15

1 Answer 1

4

The standard profiles have different names that are indexed. They are labeled PT1 through PT14. Some of those profiles have since been retired. Summer '07 was supposed to eradicate those old names (e.g. in formulas), but it looks like they never got around to fixing them in the search index. To find them, you have to search for them directly:

find {pt*} in all fields returning Profile(Name)

Which in my org returns:

Id,Name
00e50000000nkjiAAA,System Administrator
00e50000000nkjuAAA,Contract Manager
00e50000000nkjqAAA,Marketing User
00e50000000nkjpAAA,Solution Manager
00e50000000nkjnAAA,Standard User

You'll have to include pt* as part of your search term, and then you can filter them later:

find {pt*} in all fields returning Profile(Name WHERE Name LIKE 'System%')

So, your final solution will probably be a SOSL that looks like the following:

find {pt* or :searchTerm} in all fields returning Profile(Name WHERE Name LIKE :searchTerm)
3
  • 1
    So it is a case that Salesforce have forgotten to update the standard indexing for profiles... seems like a bug to me!
    – Phil W
    Oct 31, 2023 at 21:14
  • as I started on the platform in 2008, I was unaware of this. Of course, since permissions on Profiles are going away, the use case for this will be even less common in the years ahead
    – cropredy
    Oct 31, 2023 at 23:41
  • @cropredy I am a font of old Salesforce knowledge, lol. I'm looking forward to the day that profiles are no longer necessary to maintain. Just give a user the correct license and a handful of permission sets, ideally.
    – sfdcfox
    Oct 31, 2023 at 23:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .