[SalesForce] visualforce remote objects get current user ID

I am trying to use the new visualForce remote objects to get information about the current user. I have

usr.retrieve({
where: {
UserID: {
eq: ''
}
},
limit: 1
},

The problem is that I do not know how to dynamically get the userId in VF remote objects. Has anyone figured out how to do this?

Best Answer

Since you're in Visualforce context, it should suffice to say:

eq: '{!$User.Id}'

Which will be merged in by the Visualforce engine at runtime. Note that if your script is instead located in an include file, you'll need to have that value available before that script can run:

// This script should appear anywhere in the document, before the page finishes loading
window.$userId = "{!$User.Id}";

// In your script:
eq: window.$userId
Related Topic