+ Start a Discussion
AnujaAnuja 

Insert data failed through site in standard object

Hi all,

 

      I Have problem with salesforce site. I am trying to insert record in standard object through site but i am getting an error that is ,

 

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.

 

-------

 

When i am trying it through visualforcepage on platform its working fine.

 

My VF Page is,

 

<apex:page Standardcontroller="Account">
   
  <apex:form >
   <apex:pageBlock title="Account Info">
 
      <apex:pageBlockButtons >
        <apex:commandButton action="{!save}" value="Save"/>
      </apex:pageBlockButtons>
 
      <apex:pageBlockSection showHeader="false" columns="2">
        <apex:inputField value="{!account.name}" />
      </apex:pageBlockSection>
 
    </apex:pageBlock>
  </apex:form>
</apex:page>

 

 

Can anybody suggest?

 

Thanks,

 

Anuja.

bob_buzzardbob_buzzard

Have you configured the public access settings for the site correctly - i.e. have you given the public access profile create permission to accounts?

 

If that is set up, I'd imagine that the standard controller is attempting to direct you to the standard salesforce.com record view page for the newly created account, and this is requiring you to login.

AnujaAnuja

Hi,

 

      I did all CRUD settings and field level security settings for account object.

      It is still diverting control to salesforce's standard login page.

 

 

      Thanks,

     

      Anuja.

bob_buzzardbob_buzzard

So it sounds like the second part of my answer is applying - Salesforce is trying to redirect you to the standard view page for the account that you have created.  I'd image you'll need to write an extension controller where the save method redirects you to a site specific page rather than the standard page.

AnujaAnuja

Hi,

 

   I have tried with the controller and redirection to the another page but still the record is not getting saved in the Account object.

 

The code for which i have tried is -

 

VF Page ------------

 

<apex:page  showHeader="false" Controller="accController" >  
       <apex:outputPanel layout="block">        
        <apex:form>
                     <apex:panelGrid columns="2" >
                      <apex:outputLabel value="First Name"/>
                      <apex:inputText required="true" value="{!Name}"/>
                      <apex:outputLabel value="Email"/>
                      <apex:inputText required="true" value="{!Email}"/>
                     
                      <br/><br/>
                      <apex:commandButton action="{!save}" value="Contact Me"/>
         
                   </apex:panelGrid>
        </apex:form>
        </apex:outputPanel>
</apex:page>

 

 

Controller ----------

 

public class accController
{
   
    public accController() {

    }
   
    public String name { get; set; }
    public String Email { get; set; }
   
    public PageReference save()
    {
        Account objAcc = new Account();
        objAcc.Name = name;
        objAcc.Email__c = Email;
        insert objAcc;


        PageReference pr=new PageReference('/apex/MainPage');
        pr.setRedirect(true);
        return pr;    
    }

}

 

.

bob_buzzardbob_buzzard

Have you tried turning on debug logging for the public access profile to see if you are getting errors?

BeeddiskShahBeeddiskShah

As far as I know you CANNOT insert data in standard objects through sites. You can create a dummy object and insert them, keeping the standard object and the dummy object in sync using trigger.

bob_buzzardbob_buzzard

I don't think that is correct - I've just created a simple page and controller to save an account and been able to successfully insert 5 accounts via a site as an unauthenticated user - each account is owned by the guest profile associated with the site. 

BeeddiskShahBeeddiskShah

Using a authenticated user right? A direct guest user cannot create standard objects, thats my understand. Let me explore.

bob_buzzardbob_buzzard

No, as I said above, this was an unauthenticated user.

 

My understanding was that you can do this, but it isn't a good idea.

 

I'm using developer edition BTW.

bob_buzzardbob_buzzard

To speed up your exploration,  here's the page and controller I used:

 

controller:

 

 

public  class CreateAccountController 
{
	public Account acc {get; set;}
	public CreateAccountController()
	{
		acc=new Account();
	}
	
	public void Save()
	{
		insert acc;
		acc=new Account();
	}
}

 

 

 

Page:

 

 

<apex:page controller="CreateAccountController" sidebar="false" standardstylesheets="false"
    showheader="false">
<h1>Create Account</h1>
<apex:form >
<apex:inputText value="{!acc.name}"/><br/><br/>
<apex:commandButton action="{!Save}" value="save" />
</apex:form>
</apex:page>

 

 

 

salesforcemicky125salesforcemicky125

Hi Bob, I have tired with contact object i " Inserting data though the site in standard object failed" can you please provide what are the required things that has to be . We are working on Sites where enduser(Guest User) will provide his Contact deails like Email, Last Name, First name,Phone and when we Click on Save it is not saving the ContactDetails in DataBase and here we we are redirecting to another Custom Object page .

 

The code is working for saving the Record in the contact Object in Developer Edition.

Is not working with Unlimited Edition and that througth the Site we  are giving the enduser to use the site where  the End user create a record and save it in my DB. from Contact we are also redirecting to Other page we are facing the issue when we are redirecting and we cannot able tostore the Data through the Contact Object also

 

 

Here is my Code:

 

Controller:

 

public class contactControllerForEvent
{

public contactControllerForEvent() {
}

public String firstname{ get; set; }
public String Email { get; set; }
public String title{ get; set; }
public String lastName{ get; set; }
public String phone{ get; set; }


public PageReference save()
{
Contact objCon = new Contact();
objCon.FirstName = FirstName;
objCon .LastName= LastName;
objCon .Email = Email;
objCon .Phone= Phone;

objCon .Title= Title;

insert objCon ;

PageReference pr=new PageReference('/apex/contactControllerForEvent');
pr.setRedirect(true);
return pr;
}
}

 

VF Page:

 

<apex:page showHeader="false" Controller="contactControllerForEvent" >
<apex:outputPanel layout="block">
<apex:form >
<apex:panelGrid columns="2" >
<apex:outputLabel value="FirstName"/>
<apex:inputText required="true" value="{!FirstName}"/>
<apex:outputLabel value="Email"/>
<apex:inputText required="true" value="{!Email}"/>
<apex:outputLabel value="LastName"/>
<apex:inputText required="true" value="{!LastName}"/>
<apex:outputLabel value="Phone"/>
<apex:inputText required="true" value="{!Phone}"/>
<apex:outputLabel value="Title"/>
<apex:inputText required="true" value="{!Title}"/>

<br/><br/>
<apex:commandButton action="{!save}" value="Save"/>

</apex:panelGrid>
</apex:form>
</apex:outputPanel>
</apex:page>

 

 

 

 

 

 

 

salesforcemicky125salesforcemicky125
Hi Bob, Thanks with u r Example i resolved my Issue.
Yes you are Right . We can do it as what you have said i.e we can insert data through site for Standard Object also