You need to sign in to do that
Don't have an account?
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;
}
}
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.
Thanks for your respose. But I am getting this error.
Illegal view ID updatekey. The ID must begin with /
I fixed the problem but I want to fire this class after the construtor is fired. How?
I got it. Thanks