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

DML support in VisualForce


         I come across following exception while trying to insert a record in a custom object.
DML currently Not allowed.

I want to just confirm it, whether DML is allowed or not in VisualForce pages controllers ?


Mark YoungMark Young

It definately does work.

If this is a component controller, take a look at the 'allowDML' property of the component tag.

Hi Mark,

    Thanks for feedback.

Actually its a page controller and I didn't get such allowDML property for that.

Any other option ?

DML is only allowed in code invoked via an action method and is not allowed in getter/setter methods.
Nor is it allowed in the constructor of a controller.
      I am trying to implement some select queries in Visualforce page. I am trying implement search funtionality using two or more fields. I want to search by name or city (and also with both). But I am unable to get the result if one of the fields is blank.
searchTest page has the account name and city as the input fields.
And the searchtest2 page has the display in a data table.
The code is :
public class accountController {
   private String nameString;
   private String cityString;
   public void setNameString(String val1) {
    nameString = val1!=NULL?val1:NULL;
    public String getNameString() {
    return nameString;
    public void setCityString(String val2) {
    cityString = val2 != NULL ?val2:NULL;
    public String getCityString() {
    return cityString;
   public List<Account> getAccounts() {
    if ( nameString!=NULL&&cityString!=NULL )
    return [SELECT name,BillingStreet,BillingCity,BillingState,BillingPostalcode,Phone FROM Account WHERE Account.Name LIKE :nameString AND Account.BillingCity LIKE :cityString ORDER BY LastModifiedDate LIMIT 120];
    else if ( nameString == NULL  )
    return [SELECT name,BillingCity FROM Account WHERE Account.BillingCity LIKE :cityString ORDER BY LastModifiedDate LIMIT 120];
    else if ( nameString != NULL&&cityString == NULL )
    return [SELECT name,BillingCity FROM Account WHERE Account.Name LIKE :nameString ORDER BY LastModifiedDate LIMIT 120];
    return null;
    /*Account account = getAccountInfo.getAccountByName(nameString,cityString);
    return account; */
    public PageReference searchAccount() {
        return Page.searchTest2;
Please help. Thank you
Perhaps you responded to the wrong message by accident but if not what does this have to do with DML support in Visualforce ?  Please start new topics as new threads and not responses to existing ones unless it's a natural extension of the same topic - even then, however, you should consider a new thread as the more relevant the content of the thread is to the actual subject the better the chance someone facing a similar issue will find it.
Oops. Sorry ... will create a new thread. Thanks