You need to sign in to do that
Don't have an account?
Steven Houghtalen
DML error message: "DML not currently allowed"
I am new to apex coding but thought I understood most of what I need to do. I have created a vf page that displays some fields amd updates some fields. When I execute it, I get the following error: "DML not currently allowed" due to the DML "update" statement. This has me puzzeled as it works from the Anonymous Window. I would appreciate any help on this. Following is the class and VF Page. Thanks.
<apex:page controller="Test2">
<apex:form >
<apex:pageblock title="Greetings {!$User.FirstName}">
<apex:pageBlockTable value="{!Clt}" var="c">
<apex:column value="{!c.Name}"/>
<apex:column value="{!c.Gender__c}"/>
<apex:column value="{!c.Age__c}"/>
<apex:column value="{!c.SDLM__c}"/>
</apex:pageBlockTable>
</apex:pageblock>
</apex:form>
</apex:page>
public with sharing class Test2 {
Public Test2() {
}
Public List <Client__c> clt;
Integer sdlm=1;
Public List <Client__c> getclt (){
clt = [select Client__c.Name,Client__c.Age__c,
Client__c.Gender__c,Client__c.SDLM__c
From Client__c
Order by Client__c.Name DESC];
For(Client__c c: clt){
c.SDLM__c = 1;
}
Update clt;
return clt;
}
}
<apex:page controller="Test2">
<apex:form >
<apex:pageblock title="Greetings {!$User.FirstName}">
<apex:pageBlockTable value="{!Clt}" var="c">
<apex:column value="{!c.Name}"/>
<apex:column value="{!c.Gender__c}"/>
<apex:column value="{!c.Age__c}"/>
<apex:column value="{!c.SDLM__c}"/>
</apex:pageBlockTable>
</apex:pageblock>
</apex:form>
</apex:page>
public with sharing class Test2 {
Public Test2() {
}
Public List <Client__c> clt;
Integer sdlm=1;
Public List <Client__c> getclt (){
clt = [select Client__c.Name,Client__c.Age__c,
Client__c.Gender__c,Client__c.SDLM__c
From Client__c
Order by Client__c.Name DESC];
For(Client__c c: clt){
c.SDLM__c = 1;
}
Update clt;
return clt;
}
}
<apex:page controller="Test2"> action="{!myMethod}">
Here is a good post on this topic with pros/cons of options.
http://salesforce.stackexchange.com/questions/23923/call-apex-method-from-visual-force-page-not-in-constructor
All Answers
Check below post for same
1) http://salesforce.stackexchange.com/questions/28833/why-is-dml-not-allowed-in-constructor
2) http://salesforce.stackexchange.com/questions/32138/system-limitexception-dml-currently-not-allowed/32140
3) https://th3silverlining.com/2009/11/23/dml-currently-not-allowed/
Situations that may cause ‘DML currently not allowed’
Let us know if this will help you
<apex:page controller="Test2"> action="{!myMethod}">
Here is a good post on this topic with pros/cons of options.
http://salesforce.stackexchange.com/questions/23923/call-apex-method-from-visual-force-page-not-in-constructor