+ Start a Discussion
MC2014MC2014 

Querying a User within a Public sites page?

I have a public site page form that creates a case and assigns it to the owner that is query within Apex. Since, its is a public site it doesn't query anything from the user object.

Using "Site.getAdminId()" doesn't work in my case, since I am the site administrator that is not what I want.

16:09:31.169 (169671978)|SOQL_EXECUTE_BEGIN|[119]|Aggregations:0|SELECT Id FROM User WHERE Name = 'Salesforce Administrators' LIMIT 1
16:09:31.189 (189902826)|SOQL_EXECUTE_END|[119]|Rows:0
16:09:31.190 (190228383)|SYSTEM_MODE_EXIT|false
16:09:31.190 (190383656)|FATAL_ERROR|System.QueryException: List has no rows for assignment to SObject


Best Answer chosen by MC2014
bob_buzzardbob_buzzard
Do you have user sharing turned on?  That would stop your site user seeing the other users unless your extension controller was declared without sharing.

All Answers

bob_buzzardbob_buzzard
You should be able to access this information through a custom controller - I've just created a page on my site that lists all users in the system and that works fine.

Have you executed the query to ensure that there is a user named 'Salesforce Administrators' ?
MC2014MC2014
It executed ok when the VF page is native in SF, once I assigned it as a Sites page, it won't execute.

Originally that query was within the PageReference save method, so I move it to the constructor and now get the standard site  "Authorization Required" page.
Comment out that user query line, and the page load fine. So, some reason that User Object is not open in Sites.
private Id ownerId;

public SampleOrderController(ApexPages.StandardController controller) {
        ownerId = [Select Id From User Where Name = 'Salesforce Administrators' Limit 1].Id;
}


bob_buzzardbob_buzzard
Do you have user sharing turned on?  That would stop your site user seeing the other users unless your extension controller was declared without sharing.
This was selected as the best answer
MC2014MC2014
So that was it, all I had to do is share the admin user to the site guess user.