Ajax (1) Apex Class (12) Apex Trigger (2) Community (2) Home Page (1) HTML (4) Integration (3) JS (7) KB (1) Label (1) Licenses (1) Listing (1) Log (1) OOPs (5) Sharing (1) Static Resource (1) Test Class (3) URI (1) Visualforce (10)

Friday 17 October 2014

How to get Total unused User Licenses

String result;
String orgName;
String orgCountry;
         Organization orgDetails =[ select Id, Name, Country from Organization limit 1];
            Id orgId = orgDetails.Id;
            orgName = orgDetails.Name;
            orgCountry = orgDetails.Country;

        PageReference pr=new PageReference('/'+orgId);
        //called screenscraping: get the data from the page
        String rawData=pr.getContent().toString();
   String licRow = '>Salesforce</th><td class=" dataCell  ">Active</td><td class=" dataCell  numericalColumn">';
    Integer licLen = licRow.length();
  Integer pos=rawData.indexOf(licRow);
if (-1!=pos)
{
         Integer licStart = pos + licLen;
         result=rawData.substring(licStart, licStart+3);
}
Decimal lic = decimal.valueOf(result);
integer u = [select count() from user where profile.UserLicense.Name = 'salesforce' and isactive = true];
Decimal userCount = decimal.valueOf(u);
Integer totalUnused = (lic.intValue() - userCount.intValue());
System.debug('************ Licenses???? ***************** ' + String.valueOf(totalUnused));

No comments:

Post a Comment