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
dxjonesdxjones 

How to enable DML for Controller? (DML in method invoked by Visualforce page action fails)

I am hoping this is an easy question:

I am invoking an "action" when a visualforce web page is loaded.


    <apex:page contentType="text/xml" controller="MyPageController" action="{!MyUpsertAction}" showHeader="false">


From extensive tracing and debugging, I know MyPageController is working and MyUpsertAction is working
up until the moment it tries to do an "upsert".

I can't figure out how to allow DML operations initiated through a web/visualforce page.

I get the dreaded "Authorization Required" page displayed (instead of the XML my page should be serving up).

I also get an error message sent by email.

    Apex script unhandled exception by user/organization: 005A0000000IePu/00DA0000000Jcjx

    Visualforce Page: /

    caused by: System.Exception: DML currently not allowed


I am sure there is a quick fix by clicking some option somewhere on Saleseforce,
but I am really pulling my hair out trying to find it!


Please be specific about the steps I need to follow to solve this problem.

I am new to developing on Salesforce, so if you just say "enable DML for the site",

I won't have a clue where to navigate and click on the Salesforce web pages.

 

Any suggestions would be appreciated.

David Jones

dxjones@gmail.com

 

HarryHHHarryHH

Hello David,

 

did you find the problem? I have the same problem in a Visualforcepage rendered as PDF. Normally you should have a pagereference method in your page. There DML statements are allowed. But in a controller for a PDF a pageReference makes no sense, so I have the same problem as you!

 

Thanks

Harry

HarryHHHarryHH

For me I found the solution! I wrote a pageference method with return null!

 

Harry

Marc C.Marc C.

I'm running into the same wall. Could you post your controller code HarryHH?

dinesh kumar 2257dinesh kumar 2257
Actually I have tried similar way, But I am getting issue as 
Error: Method is not visible: [cres_cc_HeaderController].InActiveLightFixtureCart()
Error: Error occurred while loading a Visualforce page.
 
Visual Force page
<apex:page id="CSTN_Global_Header" applyHtmlTag="false" docType="html-5.0" sidebar="false" showHeader="false"
           standardStylesheets="false" controller="cres_cc_HeaderController" action="{!InActiveLightFixtureCart}">

Controller: 
global with sharing class cres_cc_HeaderController {
    
    public cres_cc_HeaderController(){
     
    }
    
    public PageReference InActiveLightFixtureCart(){
        //System.debug('InActiveLightFixtureCartsByUserId - ccrz.cc_CallContext ' + ccrz.cc_CallContext.currUserId);
        System.debug('InActiveLightFixtureCartsByUserId - ccrz.cc_CallContext5');
        System.debug('InActiveLightFixtureCartsByUserId - ccrz.cc_CallContext5 ' + ccrz.cc_CallContext.currUserId);
        
        return null;
    }
}

Please guide