+ Start a Discussion
CezuCezu 

Authorization Required for Public Page Error when i save record

Hi Everyone,

 

I created a VF form which will i save  field in my custom object   I'm using this page in the site here while i'm clicking the Save! button it is showing me the Authorization required page.I checked all the permissions to object ,fields,Apex class, VF all are correct.Here is my code

 

Controler :

 

public class CreateNewCandidateToVerify{
private final ApexPages.standardController controller;
private final Candidate_to_Verify__c obj;
public Attachment attachment {get; set;}

public CreateNewCandidateToVerify(ApexPages.StandardController stdController) {
this.controller = stdController;
this.obj = (Candidate_to_Verify__c)stdController.getRecord();
attachment = new Attachment();
}

public PageReference zapis(){
String val = ApexPages.currentPage().getParameters().get('recruitment');
Recruitment__c rec = [
SELECT id
FROM Recruitment__c
WHERE id = :val
LIMIT 1];
obj.Recruitment__c = rec.id;
insert obj;
Candidate_to_Verify__c added = [
SELECT id
FROM Candidate_to_Verify__c
WHERE Name__c = :obj.Name__c
AND Surname__c = :obj.Surname__c
AND Phone__c = :obj.Phone__c
AND E_mail__c = :obj.E_mail__c
LIMIT 1];
attachment.ParentId = added.id;
try{
insert attachment;
}
catch (DMLException e) {
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading attachment. You can send your CV by e-mail: e-mail adress'));
return null;
}
//obj = new Candidate_to_Verify__c();
//attachment = new Attachment();
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'Thanks for Application'));
return null;
}

}

 

VF Page 

 

<apex:page standardStylesheets="false" showHeader="false" sidebar="false" standardController="Candidate_to_verify__c" extensions="CreateNewCandidateToVerify">

 

<h1>Welcome in HR App</h1>
</center>
<h2></h2>
<br></br>
<apex:form >
<center>
<apex:pageBlock id="tst2">
<apex:pageMessages />
<apex:pageBlockSection columns="1">

<h3>Personal Data</h3>

<apex:inputField value="{!Candidate_to_verify__c.Name__c}"/>
<apex:inputField value="{!Candidate_to_verify__c.Surname__c}"/>
<h3>Contact Data</h3>
<apex:inputField value="{!Candidate_to_verify__c.Phone__c}"/>
<apex:inputField value="{!Candidate_to_verify__c.E_mail__c}"/>


</apex:pageBlockSection>
<h1>Attach your CV</h1>
<apex:pageBlockSection showHeader="false" columns="2" id="block1">
<apex:pageBlockSectionItem >
<apex:outputLabel value="File Name" for="fileName"/>
<apex:inputText value="{!attachment.name}" id="fileName"/>
</apex:pageBlockSectionItem>

<apex:pageBlockSectionItem >
<apex:outputLabel value="File" for="file"/>
<apex:inputFile value="{!attachment.body}" filename="{!attachment.name}" id="file"/>
</apex:pageBlockSectionItem>

<apex:pageBlockSectionItem >
<apex:outputLabel value="Description" for="description"/>
<apex:inputTextarea value="{!attachment.description}" id="description"/>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>

<apex:pageBlockSection >
<apex:commandButton action="{!zapis}" value="Save!">
<apex:param value="{!$CurrentPage.parameters.recruitment}" assignTo="{!Candidate_to_Verify__c.Recruitment__c}"/>
</apex:commandButton>
<apex:commandButton action="{!cancel}" value="Cancel!"/>

</apex:pageBlockSection>

</apex:pageBlock>
</center>
</apex:form>
</apex:page>

 

colemabcolemab

Cezu,

 

If you are sure that the public site user profile has create access to all of the objects that are being created, then the issue might be an exception is being thrown by your code and for security reasons the public site isn't displaying the error.

 

To see the error, log into your instance and access the page (by using the /apex/PageName url) and try inserting the record.  Any exceptions would then be shown to you on the authenticated session.

 

Another option is to have a try / catch block in your controller code that will email the exception to you.

 

Thanks

 

-----

 

Please give kudos to the authors of posts that you find helpful.

Ramesh SomalagariRamesh Somalagari
I have same problem it asking "Authorization Required".Please click this url : https://developer.salesforce.com/forums/#!/feedtype=SINGLE_QUESTION_DETAIL&dc=Mobile&criteria=ALLQUESTIONS&id=906F0000000AZYGIA4 (https://developer.salesforce.com/forums/#!/feedtype=SINGLE_QUESTION_DETAIL&dc=Mobile&criteria=ALLQUESTIONS&id=906F0000000AZYGIA4)
gbuttgbutt
I just ran into this same issue. Adding any messages to the apex page will cause an Authorization Required error. The solution for me was to change the class definition to 'without sharing'. Try this : 
public without sharing class CreateNewCandidateToVerify { ... }