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
gbu_jinigbu_jini 

Update account from Force.Com Site

I developed a Force.Com SIte that display an account in a form. I have a save button. But i receive this error when i try to save :

system.security.NoAccessException

 

My VF :

<apex:page showheader="false" controller="DemoForceComSite">
    <apex:form id="ficherenseignementform">
        <apex:pageMessages />                     
        <apex:inputHidden value="{!accountId}"/>
        <apex:outputLabel value="Raison sociale " for="RaisonSociale"/>  
        <apex:inputText id="RaisonSociale"  value="{!oAccount.name}" styleClass="inputtext" />
        <div>
             <apex:commandButton action="{!save}" value="Save"  />
             <apex:commandButton action="{!save2}" value="Save2"  />
             <apex:commandButton action="{!cancel}" value="cancel"  />
        </div> 
    </apex:form>
</apex:page>

 My controller :

public class DemoForceComSite{

    public Account        oAccount {get;set;}  
    public String         accountId {get;set;} 
      
    public DemoForceComSite() {        
        
        accountId = '001P000000WlX5O';
        try {
            oAccount = [Select Id, Name From Account where Id= :accountId limit 1];
       } catch (Exception e) {
                // Display error message
            ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.ERROR, 'Impossible de retrouver les informations nécessaires à l\'affichage de la page. Veuillez prendre contact avec votre interlocuteur.'));
            return;
        }
    }

   public PageReference save() {      
        oAccount = [Select Id, Name From Account where Id= :accountId limit 1];
        oAccount.name = 'Test';
        upsert oAccount ;  
        return null;
    }
   public PageReference save2() {    
        upsert oAccount;
        return null;
    }
   public PageReference cancel() {
        return null;
    }
}

 

Every method fails. Even the cancel method !! The rights are ok on the object.

 

It seems that the error not occurs when i withdraw all the account fields on the VF !! But i need them !!

 

Any idea ?

 

RadnipRadnip

You cannot update the accounts object using salesforce sites. Its a limitation of Salesforce Sites.

gbu_jinigbu_jini

Thanks for your answer.

 

Is there a similar limitation on the contact object ?

 

RadnipRadnip

You can check the permissions and what you can and can't do by doing the following:

 

[your name] > Setup >  App Setup > Develop > Sites > [click your site label name] > Public Access Settings

 

 

SF Expert.ax1061SF Expert.ax1061

Yopu can do this task by Wrapper Class in the same code.

 

Let me know if you need further help on this,

 

Thanks

techie.in.sf@gmail.com

Andy BoettcherAndy Boettcher

Just a heads up... 

 

Just be careful when starting to use Sites in this manner.  Technically you can do just about anything, but keep in mind the licensing restrictions on how SF allows you to use sites.  Contact your Account Rep or Partner Rep with questions.

Paul.FoxPaul.Fox

Do you know if it's still possible to do this with a wrapper class? I'd like to expose a page to let contacts update their newsletter subscriptions, which is currently tracked as fields on the lead and contact. I've tried exposing these through a special newsletter class that queries the lead or contact and then returns it to the page as just a newsletter object with boolean variables, but it still says that "This page requires authentication".

RadnipRadnip
No a wrapper class won't help, check the previous posts about how to find what permissions you have access too.