function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
abhaabha 

Authorization Required Error

I have created custom object called 'students'. I have developed the visualforce page and controller class, which accepts student details and creates a new record. It is working properly when executed from 'https://c.ap1.visual.force.com/apex/StudentForm8'.. I.e. within the account. 

When I try to load this VF page from my website, it is giving me error like

Authorization Required
You must first log in or register before accessing this page.
If you have forgotten your password, click Forgot Password to reset it.

 

I checked the following things :-

1- custom object status is set as "Deployed"

2-  the site public access settings has Read, create and edit permission on this custom object

3- the Site public access settings  Field Level security are set as "Visible" for the fields that are displaying on this page 

4-  Page is associated with my site

 

Here I am attaching my code

Visualforce page "StudentForm8"

<apex:page controller="MyController8" tabStyle="Account" >
    <apex:form >
        <apex:pageBlock mode="edit">
            <apex:pageMessages />
            <apex:pageBlockSection >
                <apex:inputField value="{!Details.name}"/>
                <apex:inputField value="{!Details.Branch__c}"/>
                <apex:inputField value="{!Details.Subjects__c}"/>
                <apex:inputField value="{!Details.Aggregate__c}"/>
            
            </apex:pageBlockSection>
            <apex:pageBlockButtons location="bottom">
                <apex:commandButton value="Save" action="{!save}"/>
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 

Controller code named "MyController8"

public class MyController8 {

    public Student__c stud { get; set; }
    public MyController8() {
     stud = new Student__c();
    }
        public Student__c getDetails() {
        return stud;
    }
    public PageReference save() {
        try {
            insert(stud);
        } catch(System.DMLException e) {
            ApexPages.addMessages(e);
            return null;
        }
      PageReference pageRef = new PageReference('http://myappmbb-developer-edition.ap1.force.com/RegiSuccess');
      return pageRef;
    }
}

 

After record creation page wasredirecting to system page showing detail new record. I thought it is creating problem as system page can't be available on website. So I redirected it to fix url "http://myappmbb-developer-edition.ap1.force.com/RegiSuccess".. RegiSuccess page is visible from my website.

 

 

In spite of all these things page is not accessible from website.

What would be the possible error?

Any kind of help would be greatly appreciated.

 

AdrianCCAdrianCC

How exatly are you accessing the form page in your site?

 

I've tried http://myappmbb-developer-edition.ap1.force.com/StudentForm8 and it loaded and worked okay for me - created a record from what I see.

 

Thanks,

Adrian

abhaabha

Thank u for your reply!!

Initially the page was not loading from website.. So I removed  [    tabstyle="Accounts"    ]  field from VF page. This removed the Authorization required error.

But now new problem has been arisen. Now website  pages are working properly. But such execution is not creating new student record in application database.

When I execute same code from  'https://c.ap1.visual.force.com/apex/StudentForm8' it is working and creating new record in database.

Will you please help me to solve this problem?

joshbirkjoshbirk

So whenever you see this disconnect between a public VF page and an authenticated one, it is usually something to do with the Guest Profile of the Site definition.  IE, a field which you can see when logged in but the guest website user cannot see...

abhaabha

Could you tell me how to give these read, create, update access to guest profile?

One more question,  one of the VF page shows all its fields when viewed as authenticated page.. But it hide some fields when viewed as public page(IE  from website). What should be done so that all fields will be accesible to the guest user?

AdrianCCAdrianCC

I think you need to check the field level security(FLS) for your objects. The fact that you can see all the fields correctly on one profile and not see all of them on another shows that some might not be visible.

 

Are you sure the profile that you are using has access to all the objects that you are using?

 

Adrian