You need to sign in to do that
Don't have an account?

Displaying only records owned by the current user
I need assistence on how to select only records owned by the current user on a visualforce page. I have tried $User and $User.Id to no avail. Please assist.
Here is my controller.
public class retrieveASNAccounts { public List<Account> getAccounts() { return [SELECT Name, First_ASN_Date__c FROM Account WHERE Account.OwnerId != null AND First_ASN_Date__c != null order by First_ASN_Date__c DESC limit 10]; } }
Here is my page.
<apex:page controller="retrieveASNAccounts"> <apex:pageBlock > <apex:pageBlockTable value="{!accounts}" var="a"> <apex:column value="{!a.name}"/> <apex:column dir="" value="{!a.First_ASN_Date__c}"/> </apex:pageBlockTable> </apex:pageBlock> </apex:page>
Thank you!
Use WITH SHARING keyword...
public class with sharing classname{
your query;
}
Now your query returns only records owned by the current user...
Cheers!!
Add condition with Query Account.ownerId =: userInfo.getUserId() ;
Thanks,
Kirtesh