Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

When i am adding header component to new visual force page then it is returning exception saying

Visualforce Error

System.LimitException: DML currently not allowed

Class.ExceptionManager.save: line 14, column 1
Class.ExceptionService.saveException: line 25, column 1
Class.BaseController.<init>: line 348, column 1
Class.SignUpController.<init>: line 79, column 1

How do i get a solution for this problem ?

<apex:page showHeader="false" controller="RequestTradeController" standardStylesheets="false" >
    <script>
        document.title = '{!$Label.lblCR} - New Trade Relationship';
    </script> 
    <c:CommonComponent />
    <apex:form >
        <h2>Request New Trade Relationship</h2>

        <table width="70%">
            <tr><td><apex:pageMessage severity="warning">Select how you would like to send your request.</apex:pageMessage>    </td></tr>
            <tr><td align="center" class="button_link bgcolor-tab"><apex:commandButton styleClass="button_style button_link" action="{!test}" value="Request New Relationship using the Seller's CashRelease ID" id="theButton1"/></td></tr>
            <tr><td align="center"><b>OR</b></td></tr>
            <tr><td align="center" class="button_link bgcolor-tab"><apex:commandButton styleClass="button_style button_link" action="{!redirectToNewTrade}" value="Request New Relationship by Sending an Email Invitation to the Seller" id="theButton2"/></td></tr>
        </table>
    </apex:form>

</apex:page>

In this is already allowing the DML. so why i am getting this error?

share|improve this question

1 Answer 1

up vote 13 down vote accepted

You need to set the allowDML attribute of your component to true for DML to be allowed by your component. Take a look at the documentation on apex:component.

For example:

Component

<apex:component controller="MyComponentController" allowDML="true">
  <apex:form>
      <apex:commandButton value="Execute DML" action="{!executeDML}"/>
  </apex:form>
</apex:component>

Component Controller

public with sharing class MyComponentController {

     public PageReference executeDML() {
         Account a = new Account(Name = 'Test');
         insert a;

         return null;
     }
}

Page

<apex:page >
    <c:myComponent />
</apex:page>

From the apex:component documentation on allowDML:

If this attribute is set to "true", you can include DML within the component. The default is "false". Allowing DML can cause side-effects that could be problematic for consumers using the component with partial page updates. When allowing DML within a component, you should include rerender attributes so the consumer can appropriately refresh their page. In addition, you should detail, in the description of the component, what data is manipulated by the DML so that consumers of the component are aware of potential side-effects.

It is also possible that the error is being caused because there is DML in a constructor which is not allowed.

It appears that the Exception is originating in your SignUpController (Class.SignUpController.: line 79, column 1) which is not the page's controller. I'd start with looking at that.

share|improve this answer
    
please see the code, then tell me why i getting this error? –  Amit Agrawal Apr 8 at 9:45
    
Thanks for posting some of your code. I updated my answer with another possibility and a suggestion. –  Peter Knolle Apr 8 at 10:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.