Salesforce APEX 获取用户 User License

Salesforce APEX get users User License

所以我正在尝试获取当前用户的用户许可,例如。系统管理员或用户等...我在这里查看并使用了其他方法,但是这些方法似乎对我不起作用。我想知道我可以从哪里开始?

我得到的错误是:

Comparison arguments must be compatible types: Schema.SObjectField, String

来自使用以下代码:

public String getOpps() {
    if(Profile.UserLicense.Name === 'Community Customer') {
        oppCheck = true;
    } else {
        oppCheck = false;
    }


    ***loop*** {
            code here
        }
    } else {
       more code here
    }
    return 'nil';
 }

这些是许可证类型,我从 API 指南 here thanks to this post 中得到它们。

  • Standard: user license. This user type also includes Salesforce Platform and Salesforce Platform One user licenses. Label is Standard.
  • PowerPartner: PRM user whose access is limited because he or she is a partner and typically accesses the application through a partner portal. Label is Partner.
  • CSPLitePortal: user whose access is limited because he or she is an organization's customer and accesses the application through aCustomer Portal. Label is High Volume Portal.
  • CustomerSuccess: user whose access is limited because he or she is an organization's customer and accesses the application through a Customer Portal. Label is Customer Portal User.
  • PowerCustomerSuccess: user whose access is limited because he or she is an organization's customer and accesses the application through a Customer Portal. Label is Customer Portal Manager. Users with this license type can view and edit data they directly own or data owned by or shared with users below them in the Customer Portal role hierarchy.
  • CsnOnly: user whose access to the application is limited to Chatter. This user type includes Chatter Free and Chatter moderator users. Label is Chatter Free.

此外,您可能会尝试一些运气:

Profile p = [Select Name from Profile where Id =: userinfo.getProfileid()];
String pname = p.name;

if(pname == 'Community Customer') {
    oppCheck = true;
} else {
    oppCheck = false;
}