This article is to provide some Important code snippets for Liferay developers. It can be used to find lots of context information like the current user, current site, languageId, userId, groupId, permissionChecker, etc. Below code snippets can be helpful to Liferay developers in their day to day life.

1) Get Theme display object

2) Get current site GroupId

3) Get Global site GroupId

4) Get current User

5) Get logged In UserId

6) Get current time zone

7) Get permission checker object

8) Get portlet display object

9) Get current portlet name

10) Get current portlet Configuration Url

11) Get portal layout ID

12) Get languageId

13) Get locale

14) Get Layout

15) Get logged In user’s Contact object

16) Get current color scheme

17) Get current Company object

18) Get current URL

if your public page’s URL is /test then above method will give output like : “/web/guest/test”

19) Get portal URL

20) Fetch categories from global site’s vocabulary by Vocabulary name

21) Fetch categories from current site’s vocabulary by Vocabulary name

22) Fetch Journal Article object by urlTitle

23) Fetch service context object in portlet class

24) Fetch template object in portlet class by templateKey