You need to sign in to do that
Don't have an account?
Jack Thomas 3
Insert Record every time
when visualforce page is loading i want to insert a record every time automatically is it possible,if possible How?
Thaks in advance.
Thaks in advance.
You have two options to do so -
Method 1: You can perform action inside the constructor of the controller to achieve that.
OR
Method 2: You can use standard action attribute while page load. As when we use the action attribute in apex:page, it executes before the constructor load.
If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer.
Regards
Ajay
All Answers
Apex Controller Visualforce Feel free to ask if you have any more doubts.
You have two options to do so -
Method 1: You can perform action inside the constructor of the controller to achieve that.
OR
Method 2: You can use standard action attribute while page load. As when we use the action attribute in apex:page, it executes before the constructor load.
If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer.
Regards
Ajay
It is not recommended to perform a DML operation neither in the action attribute of the <apex:page> visualforce component or in the constructor. The simple reason for not doing so, is any failure in the DML will prohibit your page from loading any further and disrupt the flow.
Refer the following link to understand further about this. - https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_page.htm (https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_page.htm )
Moreover, performing DML operations within a constructor of a controller is not permitted.
One of the simplest ways, that you could do it is using JQuery. Use the following code that will help you handle the error gracefully even if it occurs without having the page load to fail
Visualforce Code
Apex Controller Code
Please DO NOT forget to mark this thread as SOLVED if this answer helps resolve your query.