I have an HTML sidebar component that I'm using to inject js scripts in all standard pages. I need to be able to access global variables such as $User. How can I do this outside of a VF page?

So, I'd like to do something like this:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script type="text/javascript">
        var prof = '{!$Profile.Name}';

This is HTML content not Visualforce content so it does not go through any server-side processing such as expression replacement. So you cannot directly access Visualforce global variables.

However, it is possible to obtain server data by using AJAX Toolkit JavaScript calls such as sforce.connection.getUserInfo (that returns the profileID) and sforce.connection.query. See Show and Hide Buttons on Page Layouts for an example of how to do this.

  • That's what I was afraid of. I was trying to avoid an api call. Ok. Thank you for taking the time to answer @Keith
    – Adam H.
    Apr 15 '14 at 16:35

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.