{"id":6880,"date":"2019-02-02T12:23:20","date_gmt":"2019-02-02T17:23:20","guid":{"rendered":"https:\/\/www.jitendrazaa.com\/blog\/?p=6880"},"modified":"2019-10-22T22:49:33","modified_gmt":"2019-10-23T02:49:33","slug":"get-current-user-id-in-salesforce","status":"publish","type":"post","link":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/get-current-user-id-in-salesforce\/","title":{"rendered":"Get Current User Id in Salesforce"},"content":{"rendered":"\n<p>Quick Code Snippets of how to get <strong>Current logged in user ids<\/strong> in Salesforce<\/p>\n\n\n\n<p><strong>Apex<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: vb; title: ; notranslate\" title=\"\">\nSystem.debug(&#039;Current User Id - &#039;+UserInfo.getUserId());\n<\/pre><\/div>\n\n\n<p><strong>Visualforce<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: xml; title: ; notranslate\" title=\"\">\n&lt;apex:page&gt;\n  &lt;h1&gt;Visualforce Page&lt;\/h1&gt; \n   &lt;p&gt;UserId: {!$User.Id}&lt;\/p&gt;\n   &lt;p&gt;User Email: {!$User.Email}&lt;\/p&gt;\n&lt;\/apex:page&gt;\n<\/pre><\/div>\n\n\n<p><strong>Aura Component<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\nlet currentUser = $A.get(&quot;$SObjectType.CurrentUser.Id&quot;);\nConsole.log(currentUser);\n<\/pre><\/div>\n\n\n<p><strong>Lightning Web Components<\/strong> (LWC)<\/p>\n\n\n\n<p>Using wire<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\nimport USER_ID from &#039;@salesforce\/user\/Id&#039;;\nimport NAME_FIELD from &#039;@salesforce\/schema\/User.Name&#039;;\nimport EMAIL_FIELD from &#039;@salesforce\/schema\/User.Email&#039;;\n<\/pre><\/div>\n\n\n<p><strong>Formula Fields<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n$User.Id\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>How to get Current Logged in user Id in Apex, Visualforce, Lightning Component and Formula fields in Salesforce<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"jz_research_post":"","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[310,475,9],"tags":[337,471,311,462,464],"class_list":["post-6880","post","type-post","status-publish","format-standard","hentry","category-lightning","category-lightning-web-components","category-salesforce","tag-apex","tag-code-snippet","tag-lightning-component","tag-lightning-web-component","tag-lwc"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":4102,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/salesforce-faq-part-20-lightning-questions\/","url_meta":{"origin":6880,"position":0},"title":"Salesforce interview question related to Lightning framework &#8211; Part 20","author":"Jitendra","date":"February 4, 2015","format":false,"excerpt":"Salesforce interview questions for Salesforce developers and admin , mostly related to newly released Salesforce Lightning components and applications","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":6232,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/winter-18-automatic-styling-of-visualforce-pages-in-lightning-experience\/","url_meta":{"origin":6880,"position":1},"title":"Winter 18 &#8211; Automatic Styling of Visualforce Pages in Lightning Experience","author":"Jitendra","date":"September 6, 2017","format":false,"excerpt":"How to use lightningStylesheets attribute to render Visualforce in Lightning Experience Stylesheet","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"Winter 18 - Automatic Styling of Visualforce Pages in Lightning Experience","src":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2017\/09\/Winter-18.gif?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2017\/09\/Winter-18.gif?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2017\/09\/Winter-18.gif?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":5796,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/lightning-data-services-standard-controller-for-lightning-components\/","url_meta":{"origin":6880,"position":2},"title":"Lightning Data Service &#8211; Standard Controller for Lightning Components","author":"Jitendra","date":"July 22, 2017","format":false,"excerpt":"Best Practices for Salesforce Lightning Component. How Lightning Data Service can improve Lightning Component performance and solve inconsistent data problem without writing single line of Apex code. Demo source code, image and slides included.","rel":"","context":"In &quot;Apex&quot;","block_context":{"text":"Apex","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/apex\/"},"img":{"alt_text":"Salesforce Lightning Data Services","src":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2017\/07\/Salesforce-Lightning-Data-Services.png?fit=1045%2C395&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2017\/07\/Salesforce-Lightning-Data-Services.png?fit=1045%2C395&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2017\/07\/Salesforce-Lightning-Data-Services.png?fit=1045%2C395&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2017\/07\/Salesforce-Lightning-Data-Services.png?fit=1045%2C395&ssl=1&resize=700%2C400 2x"},"classes":[]},{"id":6222,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/use-visualforce-in-classic-and-lightning-experience\/","url_meta":{"origin":6880,"position":3},"title":"Use Visualforce in Classic and Lightning Experience","author":"Jitendra","date":"August 29, 2017","format":false,"excerpt":"How to design a Visualforce page so that It would be displayed properly in classic as well in Salesforce Lightning Experience","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"Same Visualforce in classic and Lightning","src":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2017\/08\/Same-Visiualforce-in-classic-and-Lightning.gif?fit=924%2C572&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2017\/08\/Same-Visiualforce-in-classic-and-Lightning.gif?fit=924%2C572&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2017\/08\/Same-Visiualforce-in-classic-and-Lightning.gif?fit=924%2C572&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2017\/08\/Same-Visiualforce-in-classic-and-Lightning.gif?fit=924%2C572&ssl=1&resize=700%2C400 2x"},"classes":[]},{"id":5715,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/calling-apex-method-at-regular-interval-from-lightning-component\/","url_meta":{"origin":6880,"position":4},"title":"Calling Apex method at regular interval from Lightning Component","author":"Jitendra","date":"November 10, 2016","format":false,"excerpt":"Importance of $A.getCallback and Modifying Components Outside the Framework Lifecycle","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"Calling Apex method at regular interval in lightning component","src":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2016\/11\/Calling-Apex-method-at-regular-interval-in-Lightning-Component.jpg?fit=1170%2C443&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2016\/11\/Calling-Apex-method-at-regular-interval-in-Lightning-Component.jpg?fit=1170%2C443&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2016\/11\/Calling-Apex-method-at-regular-interval-in-Lightning-Component.jpg?fit=1170%2C443&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2016\/11\/Calling-Apex-method-at-regular-interval-in-Lightning-Component.jpg?fit=1170%2C443&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2016\/11\/Calling-Apex-method-at-regular-interval-in-Lightning-Component.jpg?fit=1170%2C443&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":5737,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/use-lightning-component-in-visualforce-page\/","url_meta":{"origin":6880,"position":5},"title":"Use Lightning Component in Visualforce Page","author":"Jitendra","date":"September 22, 2016","format":false,"excerpt":"How to use Lightning Out to surface Lightning Component on Visualforce Pages","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"Use Lightning Components in Visualforce Pages","src":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2016\/09\/Use-Lightning-Components-in-Visualforce-Pages.jpg?fit=862%2C501&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2016\/09\/Use-Lightning-Components-in-Visualforce-Pages.jpg?fit=862%2C501&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2016\/09\/Use-Lightning-Components-in-Visualforce-Pages.jpg?fit=862%2C501&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2016\/09\/Use-Lightning-Components-in-Visualforce-Pages.jpg?fit=862%2C501&ssl=1&resize=700%2C400 2x"},"classes":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/6880","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/comments?post=6880"}],"version-history":[{"count":3,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/6880\/revisions"}],"predecessor-version":[{"id":6926,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/6880\/revisions\/6926"}],"wp:attachment":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/media?parent=6880"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/categories?post=6880"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/tags?post=6880"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}