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
mdinatalemdinatale 

Update record on page load

Im trying to insert data when the vF page loads, Whats the best way to do this. I either get a DML error or page not commited. Page not commited the data goes into the object but gives the error. Any help would be apreciated

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

This is generally not recommended as it can leave the page open to cross site request forgery attacks - essentially you are executing DML from a GET: http://wiki.developerforce.com/page/Secure_Coding_Cross_Site_Request_Forgery

 

That said, there's a couple of ways I've done this in the past:

 

(1) Insert a "staging" page that carries out the insert via an action method specified on the page component, then redirects to the real page.  

(2) Have some javascript executed at page load tied to an actionfunction that calls an action method to execute the DML.

All Answers

bob_buzzardbob_buzzard

This is generally not recommended as it can leave the page open to cross site request forgery attacks - essentially you are executing DML from a GET: http://wiki.developerforce.com/page/Secure_Coding_Cross_Site_Request_Forgery

 

That said, there's a couple of ways I've done this in the past:

 

(1) Insert a "staging" page that carries out the insert via an action method specified on the page component, then redirects to the real page.  

(2) Have some javascript executed at page load tied to an actionfunction that calls an action method to execute the DML.

This was selected as the best answer
mdinatalemdinatale

ive tried the action functioin way but get the same error. Can you give me a example of how you would do it. Ive seen examples but none seem to work. The data goes in but then i  get the error

 

 

 

bob_buzzardbob_buzzard

I don't have an example I'm afraid.  If you post up your code I can take a look at that.