[SalesForce] No such column ‘LastPasswordChangeDate’ on entity ‘User error

I am trying to access LastPasswordChangeDate field on the user object in my apex class. However, when i do so through my community user i am getting no such column of User. If i try through an internal user it works alright. Also, my apex class has been defined as with sharing and if i remove the same the error disappears. Can anyone please let me know the reason and how can i access the field with a with sharing definition of my class?

Best Answer

As you've discovered, you must use without sharing in order for a community user to access the User object. Since you want to use with sharing in your class, you must create a separate without sharing class and method specifically to retrieve the fields on the User object.

Related Topic