Yes you may do it in the constructor of the controller. Please let me know your specific requirement and post any codes that you may have written so far.
//THE PAGE CONTROLLER
public class YourPageController{
public void init(){
YourClassName.yourMethod1();
// OR
yourLocalMethod2();
}
public YourPageController(){
//This is the CONSTRUCTOR
//Cannot do DML here --> YourClassName.yourMethodName(); will error
}
public static void yourMethod2(){
//yourcode to insert/update here;
}
}
//COMMON CLASS FOR HANDLING DATA
public class YourClassName{}
yourMethod1(){
//or your code here;
}
}
//THE VF PAGE
<apex:page action="{!init}">
<!-- page code here-->
</apex:page>
<apex:page controller="testController" action="{!InsertOnPageLoad}"
if you find any other way please put it in commends
For the sake of clarity:
You cannot DML(insert/update/delete) within the constructor.
It must be via the action attribute on the VF Page.
Docs: https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_page.htm?search_text=apex:page (https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_page.htm?search_text=apex:page" target="_blank)