Loading

How to query on PermissionSetLicenseAssign to get map of Permission Set Licenses with User IDs

Julkaisupäivä: Oct 13, 2022
Kuvaus
This article provides three solutions to obtain the User Ids and the name of the Permission Set License assigned to them.

You can run a SOQL query, use REST Explorer (Workbench), or use an Apex sample code to email yourself a CSV file with the results of the query. 
Ratkaisu

Option 1: Run a Query

You can run this query in the Dev Console to find a list of User Ids and what PermissionSetLicenses are assigned to them.
  • Access the Dev Console
  • To open the Developer Console from Salesforce Classic:
    • Click Your Name.
    • Click Developer Console.
  • To open the Developer Console from Lightning Experience:
    • Click gear icon | Setup.
    • Click Developer Console.
  • Click on the Query Editor tab
  • Paste the query below into the input box
    • SELECT PermissionSetLicense.MasterLabel, PermissionSetLicenseAssign.AssigneeId 
      FROM PermissionSetLicenseAssign
  • Click the Execute button in the lower right-hand corner.

Option 2: Use REST Explorer

You can also do this in REST Explorer in Workbench. To do so, go to the Utilities tab and select the REST Explorer option.
  • Copy and paste the code below into Workbench and execute.
    • /services/data/vxx.0/query/?q=SELECT+PermissionSetLicense.MasterLabel,PermissionSetLicenseAssign.AssigneeId+FROM+PermissionSetLicenseAssign
  • Click Show Raw Response, which is in JSON.
  • You can copy this and save it and process it as needed.

Option 3: Use Execute Anonymous Window sample code to email a CSV file with the results of the query from Option 1. 

You can also use this sample code in the Execute Anonymous Window in the Dev Console to email a list for you.
From the Dev Console, go to the Debug tab and select the Open Execute Anonymous Window option:
  • Update the email address listed in line 1 to your email address in the code below
    • string emailAddress='YOUR EMAIL ADDRESS GOES HERE';
      string myRow;
      string myCSVFile = '';
      
      list<permissionsetlicenseassign> response = [SELECT PermissionSetLicense.MasterLabel,AssigneeId,PermissionSetLicense.ID FROM PermissionSetLicenseAssign];
      
      for (permissionsetlicenseassign result:response) {
        myRow = result.permissionsetlicense.masterlabel + ',' + result.AssigneeId;
        system.debug (myRow);
        myCSVFile += myRow + '\n';
      }
      Messaging.EmailFileAttachment csvAttachment = new Messaging.EmailFileAttachment();
      Blob myBlob = blob.valueOf(myCSVFile);
      String myName = 'UserID and Wave Permission Set License List.csv';
      csvAttachment.setFileName(myName);
      csvAttachment.setBody(myBlob);
      Messaging.SingleEmailMessage myEmail = new Messaging.SingleEmailMessage();
      String[] toAddresses = new String[]{emailAddress};
      String subject = 'UserID and Wave Permission Set License List CSV';
      myEmail.setSubject(subject);
      myEmail.setToAddresses(toAddresses);
      myEmail.setPlainTextBody('UserID and Wave Permission Set License List CSV');
      myEmail.setFileAttachments(new Messaging.EmailFileAttachment[]{csvAttachment});
      Messaging.SendEmailResult[] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[]{myEmail});
  • Click Execute in the lower right-hand corner of the Anon Exec Window
  • Check your email
  • Download the file
  • Use the data as needed


See Also:
Find users with permission set licenses



 
Knowledge-artikkelin numero

000383181

 
Ladataan
Salesforce Help | Article