I am trying to create a small authentication on my force.com site so that I don't have any random person accessing the site/visualforce page unless they are currently logged into Salesforce. Also if they are logged into Salesforce their profile has to be a certain one to view the page or they will get sent to the standard unauthorized page.
I am getting an error in the controller telling me that Unauthorized page doesn't exist when it is a standard page in sf. Am I doing that wrong?
This is the part of the code throwing the error:
pagereference pageref = new pagereference(Unauthorized);
pageref.setredirect(true);
return pageref;
Here is my controller: public class GRIController {
public List<String> Calls;
public GRIController(){
//find authorized profile
Boolean auth = Boolean.valueOf(ProfileCheck());
if (auth == true)
{
//If profile is authorized query for data
Query();
Refresh();
}
else
{
//Profile is not authorized send to unauthorized page
pagereference pageref = new pagereference(Unauthorized);
pageref.setredirect(true);
return pageref;
}
}
public void Query(){
//Query for Data
String soql = 'Select attendence, Contact.name, from Campaignmembers GROUP BY CampaignDate ORDER BY DSC';
Calls = database.query(soql);
}
public static String GetProfileCheck(){
String ReturnVal;
String Pro;
Pro = [Select Name from Profile where ProfileId = :User.ProfileId()];
if( Pro == 'Chatter Free User' || Pro == 'System Administrator' || Pro == 'GRI'){
ReturnVal = true;
}
else{
ReturnVal = false;
}
return ReturnVal;
}
}