Study for the Salesforce Platform Developer Exam. Study with flashcards and multiple choice questions, each question has hints and explanations. Get ready for your exam!

Practice this question and more.


Which method can be used to retrieve the current user's contact information in Apex?

  1. Contact.getCurrentUserContact()

  2. UserInfo.getUserId()

  3. System.UserInfo.getUserName()

  4. Account.getCurrentUserAccount()

The correct answer is: UserInfo.getUserId()

To retrieve the current user's contact information in Apex, the best approach is to first obtain the current user's ID using the UserInfo.getUserId() method. This method fetches the unique identifier for the user who is currently executing the Apex code. Once the user ID has been obtained, you can use it to query the associated contact details, typically using a SOQL query to fetch the relevant contact record. This two-step process involves first acquiring the user ID, and then using that ID to gather contact information from the Contact object. The other provided options do not serve the purpose effectively. For instance, the first choice suggests a method that does not exist in the Salesforce API. The third option retrieves the username of the current user but does not provide contact details. The fourth option refers to an account retrieval method which is not relevant for accessing user-specific contact information. Thus, the most reliable and appropriate choice for getting to the user's contact information starts with identifying the user through their ID.