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
CloudHuggerCloudHugger 

VF Controller Action method not allowed any DML statements

Hi All,

 

I have a site up, and a VF page with custom controller on that site.

The page controller accesses custom objects only, all of which are accessible to the site guest user profile. During debugging I have ALL possible permissions on.

Within the controller I have a PageReference method that attempts to upsert a record to one of these custom objects.

AUTHORIZATION REQUIRED error ARRRRHGHGHGHGHGHGH

 

Any suggestions re next steps?  Doing my head in!

 

Cheers,

CH

 

 

Alok_NagarroAlok_Nagarro

Hi,

 

Pls make sure your VF page and controller are added in guest user profile and VF page in the site.

CloudHuggerCloudHugger

Thanks for the suggestion.

 

I didnt mention that I had the VF page and class available to the site guest user profile already.

 

- in desperation I have added access to everything to the site guest user, and STILL DML not allowed. The DML action itself is an insert to a custom object which I have given full access to the site user. I have ensured all fields are accessible to the site user profile also, and there are no validation rules - in other words, nothing in place that should stop the insert process assuming user allowed to access the object.

 

Incredibly frustrating! :)

 

I have also written 100% test coverage that runs the DML statements as a sites guest user, and all works as designed during testing.  However, if I load the sites page in a different browser window I get the 'Authorisation Required'  message.

Alok_NagarroAlok_Nagarro

Hi,

 

Now you need to make sure 2 things-

1. Your Object which you r using in this page is in "deployed" mode rather than "development".

2. You ar not getting any exception in this page, you can see this in debuglog available from setup--> Administator Setup--> Monitoring  -> DebugLog. From here create new debuglog for site guest user.

gitguygitguy

Ever get this working?  I'm trying to upsert a visitor comment to a custom object (outside the controller's constructor) and keep getting DML not allowed.

 

My unit test is straight forward...

 

static testMethod void simpleTest() {
        PageReference pg = Page.blank;
        pg.getParameters().put('organizationId', 'anId');
        pg.getParameters().put('organizationName', 'aName');
        Test.setCurrentPage(pg);
        
        FBController aController = new FBController();
        string response = aController.getResponse();
        Dom.Document doc = new Dom.Document();
        doc.load(response);
        Dom.Xmlnode root = doc.getRootElement();
        system.assertEquals('response', root.getName());
    }

 And it runs perfectly.

 

I think the problem has something to do with guest user permissions.  If I were attempting the DML inside the constructor the unit test would also fail.