-1

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?

  • Which type of user are you trying to query when running the code as community user, is it a standard user or the logged-in community user or an external user from another community ? – Shamina Dec 10 '19 at 10:03
  • It is the logged in community user itself. @Shamina – Krish Gambhir Dec 10 '19 at 10:56
  • How are you trying to access the field? Query? Updating? Looking at the field on Workbench we can see more information about the field. Also if you look at LastPasswordChangeDate on User Fields reference, 'This read-only field appears only for users with the Manage Users permission.'. We most likely need more information such as your use case, objective for the code and a snippet too – David Picksley Dec 10 '19 at 11:42
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.