-2

I have scenario to find the remaining license in salesforce.I have found the count of used licenses by below query

Integer licenses =[SELECT COUNT() FROM User WHERE Profile.UserLicense.Name = 'Force.com - Free' AND IsActive = true];

Now i need to the remaining "Force.com - Free" licenses available in my org

2

You can query the UserLicense table to get at this data:

UserLicense ul = [select TotalLicenses, UsedLicenses from userlicense where Name = 'Force.com - Free'];

From there, you need to subtract usedlicenses from totallicenses to get the number of free licenses.

Alternatively, use one query:

AggregateResult res =
    [SELECT COUNT(Id), MAX(Profile.UserLicense.TotalLicenses) total, 
            MAX(Profile.UserLicense.UsedLicenses) used 
     FROM User 
     WHERE Profile.UserLicense.Name = 'Force.com - Free' AND 
           IsActive = true GROUP BY Profile.UserLicense.Name];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.