3

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;

        }


}
1
  • 1
    Maybe I'm not understanding the use case here, but isn't this type of stuff exactly what profile permissions were made for? If you don't want the page accessible anonymously, simple remove the Visualforce page from the Site Guest User's permissions. Jun 10, 2013 at 20:23

1 Answer 1

4
PageReference pageref = new PageReference('/apex/Unauthorized');

Or better still

PageReference pageref = Page.Unauthorized;
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .