Search code examples
liferayliferay-6

How to get RoleId using Role Name in liferay?


Is there any method where I can get the RoleId using Role Name? I have created some custom roles on my portal, like "Project Manager", "Client" and "Delivery Head". Now I need to get the respective role of these custom roles programmatically using Role Name.

Any suggestions?


Solution

  • You can use RoleLocalServiceUtil.getRole(companyId, name) method to get the role object (instance of RoleModel). If you need the id, call role.getRoleId().

    Company id can be obtained by calling ThemeDisplay.getCompanyId().