Is it possible to get field value by SOQL query only if has some specific value or type?

Following example query:

SELECT Id, License.Name FROM PermissionSet

returns permission sets with field License.Name not matters if it is UserLicense or PermissionSetLicense. I wonder if it is exist SOQL instruction for that propose or I have to loop through all records by Apex code and set specific field values to null?

1 Answer 1


As per docs the LicenseId:

The ID of either the related PermissionSetLicense or UserLicense associated with this permission set.

But Salesforce does not provide any documentation on the License object (or whatever it is)

So the closest you can get is use the IN operator

SELECT Id, License.Name
FROM PermissionSet
WHERE LicenseId IN (SELECT Id FROM UserLicense)
  • I know that @eduard. I need all Permission Sets with UserLicense and PermissionSetLicense but display only UserLicense names. With IN operator and your exmple I get only Permission Sets with User Licenses. Jul 21, 2018 at 9:15
  • 1
    Hmm, that seems to be impossible with SOQL. Unlike SQL it does not allow conditional display of a field value or UNIONs. So you only option is Apex and Lists I suppose.
    – Eduard
    Jul 21, 2018 at 9:28
  • IMHO It is serious weekness of SOQL Jul 21, 2018 at 10:39
  • 2
    @Eduard You can't do License.Id but you can do LicenseId. There is a difference between the two.
    – sfdcfox
    Jul 21, 2018 at 19:00
  • @sfdcfox Thank you for your note. I updated my answer accordingly.
    – Eduard
    Jul 21, 2018 at 19:27

You must log in to answer this question.

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