function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
tyler_jenningstyler_jennings 

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).

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

 

SuperfellSuperfell
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.
tyler_jenningstyler_jennings
I still get an exception with this query:

Profile p = [select UserLicense from Profile Where id = :UserInfo.getProfileId()];
SuperfellSuperfell
what's the exception ?
tyler_jenningstyler_jennings
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
TehNrdTehNrd
Use:  UserLicenseId

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


Jason

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

tyler_jenningstyler_jennings
Cool, that helps. What if I want the name of the license type?
TehNrdTehNrd
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
 http://community.salesforce.com/sforce/board/message?board.id=apex&message.id=912
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?