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
Sascha DeinertSascha Deinert 

DML currently not allowed

Hi,

I like to add the information 'Kon' to the custom object 'Stats__c' if I call the visualforce page.
But I get the error: DML currently not allowed.

Could you help me.


Thanks,
Sascha
 
public class Stats_class {

public Stats_class() {

Stats__c sta = new Site__c();
sta.Site__c = 'Kon';
INSERT sta;

}

}
 
<apex:page controller="Stats_class">

Stats

</apex:page>

 
Chandra Sekhar CH N VChandra Sekhar CH N V
Shouldn't line 5 be 
Stats__c sta = new Stats__c ();
Sascha DeinertSascha Deinert
But if I delete this line, I get the error.
Variable does not exist Seite__c.

 
Waqar Hussain SFWaqar Hussain SF
public class Stats_class {

public Stats_class() {

Stats__c sta = new Stats__c();
sta.Site__c = 'Kon';
INSERT sta;

}

}
Sascha DeinertSascha Deinert
@vickey, that is the same code if I mentioned in my first post.
Chandra Sekhar CH N VChandra Sekhar CH N V
@Sascha, you mentioned "Variable does not exist Seite__c." please check the API name of the custom field.
Waqar Hussain SFWaqar Hussain SF
your_object_Name__c sta = new your_object_Name__c();
sta.object_field_name__c = 'some test text';
INSERT sta;