You need to sign in to do that
Don't have an account?
CosC
how to get logged in user id in visualforce page ?
I need to show list of open cases for logged in user so i used below query & it does not work.It does not show any cases. I am using Java Script & HTML5 .
var sreas = UserInfo.getUserID();
SELECT Id, AccountId, CaseNumber, OwnerId, Reason, Status, Subject, Description, ContactId, Priority, Origin from Case WHERE OwnerId = \''+sreas+'\' Order by CaseNumber asc
You can make use of global variable to access user id in vf page as {!$User.Id}
For more information please go through https://www.salesforce.com/us/developer/docs/pages/Content/pages_variables_global_user.htm
If you are trying to access it in your JS function you can do somthing like
Thanks,
N.J
All Answers
You can make use of global variable to access user id in vf page as {!$User.Id}
For more information please go through https://www.salesforce.com/us/developer/docs/pages/Content/pages_variables_global_user.htm
If you are trying to access it in your JS function you can do somthing like
Thanks,
N.J
List<case> accList= [SELECT Id, AccountId, CaseNumber, OwnerId, Reason, Status, Subject, Description, ContactId, Priority, Origin from Case WHERE OwnerId =: Userinfo.getUserId()];
Arun & N.J I tried both the option it did not work. Below is my code after the change. Can you please let me know what is wrong in my query
Controller:
public class CaseExtension
{
public Boolean refreshPage { get; set; }
public ApexPages.StandardController stdCtrl { get; set; }
// added to get user id
public String userid{get;set;}
public CaseExtension(ApexPages.StandardController std) {
stdCtrl=std;
// initialize the refresh value as false
refreshPage = false;
userid = Userinfo.getUserId();
}
public PageReference save()
{
PageReference pRef = stdCtrl.save();
if (pRef != null) {
// set this value last, after successful saving to cause the VF page to show the javascript block
refreshPage = true;
}
//refreshPage = true;
return null;
}
}
Visualforcepage & JavaScript code:
function getAllCase() {
var sreas = {!$User.ID};
alert('{!userid}');
Case.fetch('soql','SELECT Id, AccountId, CaseNumber, OwnerId, Reason, Status, Subject, Description, ContactId, Priority, Origin from Case WHERE OwnerId = \''+userid+'\' Order by CaseNumber asc ',function() {
showCase(Case.data());
});
}
var Case = new SObjectData();
Case.errorHandler = displayError;
$j(document).ready(function() {
regBtnClickHandlers();
getAllCase('{!userid}');
});
function getAllCase(sreas) {
//var sreas = {!$User.ID};
//alert();
Case.fetch('soql','SELECT Id, AccountId, CaseNumber, OwnerId, Reason, Status, Subject, Description, ContactId, Priority, Origin from Case WHERE OwnerId = \''+sreas+'\' Order by CaseNumber asc ',function() {
showCase(Case.data());
});
}