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
ShivaShiva 

System.Exception: DML currently not allowed

Hi,

 

I am getting System.Exception: DML currently not allowed

 

I am trying to update custom object from custom controller and I am getting the above error. I looked at the solutions and people suggested to use action from the page. But it won't work for me.

 

This is what I am trying to do.

 

I am sending a SOAP messages to my server (local) and I am getting the status from the same server based on the task executed at the server. I get two status(Yes/NO). I want to perform update if the status is 'Yes'

 

How to call update function from the action or any other way to do this?

 

Controller:

======

 

public class cs_LicenseKey {
       
    public cs_LicenseKey(ApexPages.StandardController controller) {

    }

 

    public cs_LicenseKey() {


       String strPageId = ApexPages.currentPage().getParameters().get('id');

       //

       if (Return value from SOAP is true)
          updateLicenseKey(strPageId,'Yes');

  }

 

 

void updateKey(String id,String St)
     {
         cs_Key__c lk = [select GenStatus__c
                from cs_Key__c LK
               where id =:id];
                               
         lk.GenStatus__c = St;
         update lk;
     }

 

 

}

Richie DRichie D

Hi,

 

You aren't allowed to do any DML inside a constructor. To get around this you can use user initiated code (e.g. via a  command button to call a method) or the page action attribute. see below:-

 

public class cs_LicenseKey {

public cs_LicenseKey(ApexPages.StandardController controller) { }

 

public void updateKey() {

String strPageId = ApexPages.currentPage().getParameters().get('id');

// if (Return value from SOAP is true) {

cs_Key__c lk = [select GenStatus__c from cs_Key__c LK where id =: strPageId]; lk.GenStatus__c = 'Yes;

update lk;

}

}

In your VS page:-<apex:page action="updateKey" ...>

.

.

 

Hope this helps.

R. 

 

 

ShivaShiva

Thanks for your respose. But I am getting this error.

 

Illegal view ID updatekey. The ID must begin with /

ShivaShiva

I fixed the problem but I want to fire this class after the construtor is fired. How?

ShivaShiva

I got it. Thanks