Hope this will be useful !!!!
OR
Stay tuned for more complex query using dynamic query API !!!
DynamicQuery query = DynamicQueryFactoryUtil.forClass(User.class, PortalClassLoaderUtil.getClassLoader());
query.addOrder(OrderFactoryUtil.desc("userId"));
List<User> result = UserLocalServiceUtil.dynamicQuery(query);
for(User userList : result){
System.out.println("....................."+userList.getFirstName());
}
OR
DynamicQuery query = DynamicQueryFactoryUtil
.forClass(QuestionGroup.class);
Criterion defaultCompanyId = RestrictionsFactoryUtil.eq("companyId",
Utility.getDefaultCompanyId(request));
Criterion companyId = RestrictionsFactoryUtil.eq("companyId", Utility
.getCompanyId(request));
Criterion criterion = RestrictionsFactoryUtil.or(defaultCompanyId,
companyId);
criterion = RestrictionsFactoryUtil.and(criterion,
PropertyFactoryUtil.forName("subjectId").eq(subjectId));
query.add(criterion);
Stay tuned for more complex query using dynamic query API !!!