+ Start a Discussion

Accessing LicenseType attribute of Profile from Apex code doesn't work

Someone tell me why this won't compile, I can see the LicenseType column in the apex explorer.  I can also run the below SOQL query fine (minus the where clause).

Profile p = [Select p.LicenseType from Profile p where id = :UserInfo.getProfileId()];


LicenseType doesn't exist in the 10.0 api, If you tell it you're using the 9.0 api (exactly how you do this depends on what tool you're using), then LicenceType will be valid, and it'll compile.

LicenseType was replaced by UserLicense in the 10.0 API, you could switch to using that instead.
I still get an exception with this query:

Profile p = [select UserLicense from Profile Where id = :UserInfo.getProfileId()];
what's the exception ?
Straight out of Eclipse:

Compilation error: No such column 'UserLicense' on entity 'Profile'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names. QC Sandbox/Apex Triggers ClosedCaseModificationCheck.tgr line 2 1187981866252 125
Use:  UserLicenseId

Profile p = [select UserLicenseId from Profile Where id = :UserInfo.getProfileId()];


Message Edited by TehNrd on 08-24-2007 01:31 PM

Cool, that helps. What if I want the name of the license type?
I think that would require another SOQL query on the UserLiscense object but if someone else knows for sure  feel free to jump in.

If this is in reference to your other thread
you don't really need the name. If you don't want a portal user to be able to edit a record you could do something like:

Warning: pseudo code (not even close to syntactically correct)

if(p.UserLiscenceID == 100T409dckdkasuf93 && case.Status == Closed){
    case.AddErro('You dont have permission');

Where that 100T49...is the portal user license type.

If this is all you are trying to do I would strongly recommend using out of the box salesforce.com functionally before turning to Apex if possible. Could you just create a separate page layout for portal users that does not give the ability to edit the case?