I understand that we cannot have dml statement in controllers constructor. But in my case, i have a query string which is used to run our pages. So my code reads the querystring variable in the controller and has to do dml db updates to set the screen driver log. Like an e.g https://c.cs15.visual.force.com/apex/ABCON?pageName=ABCON&ApplicationId=a0we00000001YTZ&Language=EN&initDriver=N I need to make sure that i have a method say executeqrystring which i should execute first time when the query string is invoked on the browser and after that i should not execute that method at all till the request scope dies. I tried this on the controller but it fails due to dml. So how can i execute a method which can run only first time only in a controller? Any tips on this would help..I tried static but still does not work.


What about using the action attribute on your page? Then you could still perform your queries, albeit not in the constructor.


<apex:page controller="AbconController" action="{!doDml}">
  <!-- ... -->


public with sharing class AbconController {

  public AbconController() {
    //non DML calls

  public void doDml() {
    //your DML here

  • You might want to clarify that multiple constructors can be defined for the same controller. The DML method is calling a different constructor for the controller class. – crmprogdev Apr 8 '13 at 13:37
  • Different constructor @crmprogdev? Also this will get blown out of the water in security review process ;) – bigassforce Jan 2 '14 at 4:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.