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
nobodynobody 

DML currently not allowed

Hi,
 
I am trying to insert a new entry in my database with the insert call. but I always get the 

DML currently not allowed

message.

I just fill the customer object fields and call insert like following:

Custom__c custom=new Custom__c();

custom.name='blabla';

custom.value='blabla';

insert custom;

Does anyone knows how to solve this problem. Thanks in advance.

 

bye

 

 

nobodynobody
I am trying to use the DML statement in a Visualforce controller (not actually a trigger)
 
This is the code:
public class PostXMLCtrl {
public class Ent
{
String name;
String hello;
}
public String ent;
 
public String getName() {
return 'PostXML_Ctrl';
}
public PageReference postxml()
{
return Page.PostXML1;
}
public String getEnt()
{
return this.ent;
}
public void setEnt(String str)
{
this.ent=str;
}
 
public String getXml1(){
String ents;
Post_XML__c post=new Post_XML__c(name='hh', hello__c='wel');SObject[]
sobj=new SObject[1];
sobj[0]=post;
insert post;
//SaveResult[] res=binding.create(sobj);
return ents;
}
 
}
 
Thank you very much. The controller is not finished, but if the insert succeeds it should return "Ok" or something like that...
 
 
TehNrdTehNrd
Since the controller is a class make sure the profile you are using has access to that class. Not sure if this will fix it but it is worth checking.
mtbclimbermtbclimber
DML is not allowed from an accessor method (in this case a getter) in your controller. Move your DML to an action method and have it called from one of the action based components: commandLink, commandButton, actionSupport or actionPoller.

This is more of a visualforce specific issue so I will move this thread to that board.
adam_purkissadam_purkiss

Additionally, when using a component you must set allowDML to true:

 

 

<apex:component controller="IdeaElement_Extension" allowDML="true">

 

 

 

 

Dinesh Kumar 469Dinesh Kumar 469
@adam thanks for your answer :)