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 while inserting custom objects from website

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.

imutsavimutsav

Did you check the status of the site if it is active. If yes then try to run the site by clicking on the site URL eg.
Setup->App Setup->Develop->Sites->under site URL click on the URL and see if it is working.

 

Also in your VF page security do add your Customer Portal profile.

Thanks
Utsav

[Do mark this answer as solution if it works for you and give a kudos.]

abhaabha

Thank u for your reply!!

I checked my site as per youe guidence. My site is active. And it is working properly.

 

Changed Problem

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. When I execute this code from  'https://c.ap1.visual.force.com/apex/StudentForm8' it is working and creating new record in database, new record is directly visible in database. When tried on website, pages are working properly. But such execution is not showing newly created student record in application database. When we refresh database, it doesn't show new record. But if I select "All" and clicked on "Go" button, it shows that newly created record.

 

Why it doesn't show directly in database?

 

About customer portal

I am not using customer portal. Page is available for 'System admin' and 'Catalog Profile'.. where 'catalog' is my site name.

Whether I need to give any access to guest user? How to give access to this guest user profile?

 

Will you please help me to solve this problem?

ShahTheTrainerShahTheTrainer

With REFRESH, your newly created record will be displayed, you need not change the listView ie. All.

     next time, after inserting the record, try REFRESH button, it may take some time, but it will refresh.

 

And, If you want to use the TabStyle of Account, go to-->publicAccess settings, check Read checkbox against Accounts.