Getting the Address of a User

If you want to retrieve the address of a user in liferay, you have to use the AddressLocalServiceUtil with the contactId of the User - ignore the UserId. Liferay is able to connect addresses to more entities than just users, so you need to use the fabulous "classNameId - classPK" connection once again:

Here is the code:

long classNameId = ClassNameLocalServiceUtil.getClassNameId(Contact.class);

long contactId = user.getContact().getContactId();


List<Address> address= 

This should return only one result - the address of the User you want to have.

If you like this tutorial it would be very nice, if you could click on some of the google ads you see on the right side. It helps me run this block and motivates me ;)

If you have any questions, feel free to leave a comment.