You need to sign in to do that
Don't have an account?
tulasiram ch
How we can insert the data when VisualForce page is initiated...Please help me i am learning visualforce page....
Suppose i opened visualforce page , That insert the data into the DataBase. Is it possible in VisualForce?
You are right it is mentioned about not a good practice.
You could also share your business process in different thread ( if possible) which force you to do dml on VF page load.
Here is sample code:
And controller:
Thanks
Gulshan Raj
All Answers
Inserting data into an object through visual force is done by form tag.
- In the above example, the first name is an input field where user types in the data
- for submit button, we need to write a method to insert the data.
- So the background logic is taken care by Apex controller which u need to write an Apex class for fetching the data and inserting.
Hope it will be helpful.Please mark it as best answer if the information is informative.
Best Regards
Rahul Kumar
You can use page directive action function to insert data during page initialization.
inside myController write function doInsertData which insert data.
For know more about <apex:page visit https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_page.htm
Thanks
Gulshan Raj
We the experienced developer use page action to process some business logic before page get visible (render). We also use it to redirect to the page based on record data.
Please let me know if you have any question.
Thanks
Gulshan Raj
You are right it is mentioned about not a good practice.
You could also share your business process in different thread ( if possible) which force you to do dml on VF page load.
Here is sample code:
And controller:
Thanks
Gulshan Raj