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
sk kumarsk kumar 

inside a constructor if i want to dml will work or not??

is it possible to do insert operation inside a constructor..plz suggest
Abhinav GuptaAbhinav Gupta
Ideally DML is a bad idea in constructor of Apex Controllers/Extensions, they are bound to UI and a page load is not correct time to do any DML. Still if you want to hack around it, you can use <apex:page> "action" attribute and add method to do the required stuff, here is quick snippet

<apex:page  action="{!nameOfApexMethodWhichWillBeFiredAfterConstructor}">

Note: This page init action approach will be 99% rejected in salesforce security review.
I was thinking of using this approach (using page acction attribute) to capture the parameter value from the url. My scenario is that I am redirected to a visualforce page from external website with the authentication code in the url, so I need to get that code and save it on the record.