+ Start a Discussion
Abhilash Mishra 13Abhilash Mishra 13 

Authorization error in sf site while inserting a record

I am working on force.com site. i have a method which insert a record. user have all the permission CRUD and all fields are visible. when this method is called by commandlink it work. when call by any other method with in the class. site give autorisation error.
How can i Fix this. when i do this.
<!-- Visual force active site home page-->

<apex:page controller="tempcontroller">
<apex:commandbutton value ="insert" action="{!ins}">
</apex:page>


<!-- visual force controller--->

public with sharing tempcontroller{

tempcontroller(){

}
public void ins(){
 position__C pos = new postion__C(name'test');
inser pos;

}

}
the above code works fine but if i do following
 
<!-- Visual force active site home page-->

<apex:page controller="tempcontroller">
<p> this is a page</p>
</apex:page>


<!-- visual force controller--->

public with sharing tempcontroller{

tempcontroller(){

}
public void check(){
ins();

}
public void ins(){
 position__C pos = new postion__C(name'test');
inser pos;

}

}

this gives autorisation error . 
how can i solve this please help

 
Best Answer chosen by Abhilash Mishra 13
logontokartiklogontokartik
Can you let me know how you are calling ins() method? I see that a new method check() is defined, but how are you calling check()? One thing to keep in mind is that you cannot do DML's inside a constructor. If thats what you are doing?

Also please check if the Sites Guest User has access to the Apex Class and the Visualforce page.

Thank you

All Answers

logontokartiklogontokartik
Can you let me know how you are calling ins() method? I see that a new method check() is defined, but how are you calling check()? One thing to keep in mind is that you cannot do DML's inside a constructor. If thats what you are doing?

Also please check if the Sites Guest User has access to the Apex Class and the Visualforce page.

Thank you
This was selected as the best answer
Abhilash Mishra 13Abhilash Mishra 13
well the problem is solved. it was becuse DML Was not allowed in check  method.

Thanks