+1 vote
32 views
by (163k points)

I am creating users from a trigger. I need to enable the Salesforce CRM content feature for that user. before assigning that permission, I need to check the remaining licenses for the Salesforce CRM content user license.

Is there any way to get the remaining or available licenses for the 'Salesforce CRM Content User' license?

1 Answer

+1 vote
by (163k points)
 
Best answer

License information can be obtained from the UserLicense object

The following code snippet will give you the remaining licenses

List<UserLicense> uList = [select Id, Name, UsedLicenses, TotalLicenses, LicenseDefinitionKey from UserLicense];
    
    for(UserLicense ul : uList){

        System.debug('UsedLicenses: ' + ul.UsedLicenses);
        System.debug('TotalLicenses: ' + ul.TotalLicenses);
        System.debug('Name:' + ul.name);
 }

An easier way of getting this information is from the UI

Navigate to Setup > Company Settings > Company Information > Scroll to the Feature Licenses section and check the Remaining Licenses count for Salesforce CRM Content User Licenses available within your Salesforce org.

enter image description here

Welcome to Memory Exceeded, where you can ask questions and receive answers from other members of the community.
...