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
Nag22Nag22 

How to save live data automatically in salesforce

Hi

I am working on a requirment where list of questions with options(radio, checkbox, freeText) should be displayed in the page, when ever user enters the responses
that responses should be saved in the database automatically.


For that I am using autosave (action pollar with 5 seconds), then what happens is we have some validations on record saving like phone number should be 10 digits.
If I enter 5 digits  AUTOSAVE has performed and giving error.

Is there any alternative to saving the live data automatically while typing the telecaller.
bob_buzzardbob_buzzard
Much depends on what you mean by live data and autosave.  If you want to save as soon as a user completes a question, you'd need to attach onblur event handlers to all questions.  This will invoke your JavaScript when the user tabs off of the question, or clicks into another question etc.  You can them execute an actionfunction to submit the form. 

If you want to save each time the user types anything, you'd need a keypress or keyup handler for each question, and you'd also need to execute some client side validation to see if the data was in a position to be submitted (i.e. passed the simple validation such as the phone number having 10 digits). One downside to this is that you are replicating validation from the server in the client.
Nag22Nag22
Thank you Bob for your valuable reply, What you suggested is working,

I tried with onKeyPress event of open text area, when ever I enter any leter its hitting the database every time . onKeypress event is taking some time , every letter typing  we hitting the database. Coulu you please tell me , Is it a good practice?
bob_buzzardbob_buzzard
You should change your onkeypress event handler to call some local JavaScript that checks the number of characters entered into the field.  If its less than a sensible amount, simply return rather than executing the actionfunction.