Salesforce | How to get the User Informations like ORG_ID, User_ID etc in VisualForce code

| By Webner

To get the active user info or org info in Visualforce code one of the best programming practice is to get the values from the controller class of the Component.

Here is sample controller class:

public with sharing class GetUserInfo
    // getters and setters for the variables
       Public string orgID {get;set;}
       Public string userID {get;set;}
       Public string s3path {get;set;}

    public getUserInfo()
        orgID = UserInfo.getOrganizationId() ;    // getting the current org_id
        userID =UserInfo.getUserId();                  // getting the current user_id
        s3path ='salesforcedata/'+orgID+'/'+userID;  // A custom variable to be passed to external Api
        //system.debug('orgID ==== ???  '+s3path);

Our VisualForce Component:

<apex:component Controller="GetUserInfo" allowDML="true" rendered="true">

// We need to access the s3path  here within our script
// we need to use the JSENCODE function to access the variable from the controller class
var orgId = '{!JSENCODE(s3path)}';
alert("orgid is == " + orgId);

Webner Solutions is a Software Development company focused on developing CRM apps (Salesforce, Zoho), LMS Apps (Moodle/Totara), Websites and Mobile apps. If you need Salesforce customization, App development or any other software development assistance please contact us at

Leave a Reply

Your email address will not be published. Required fields are marked *