Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Salesforce
  3. Question
Salesforce

How to run the execute controller method during [removed] event?

Asked by David Edmunds May 1, 2023 603 views 1 answer
Share

About this question

 I have a visualforce page that runs calculations and stores them in an sObject as "temporary" until a user clicks a Save button, which removes the temporary flag. This was done because the calculations take longer than the max CPU time limit available, and a batch process does the calculations while the page polls for results to be completed.


My issue is that when a user doesn't save the records, and navigates away from the page (clicks any link, closes the window, etc), I want to delete the temporary records.

I've tried doing JS Remoting like this, but it didn't work:

[removed] = function() {
    // delete the temporary records.
    Visualforce.remoting.Manager.invokeAction('{!$RemoteAction.MyController.deleteTemporaryRecords}','{!reportId}',handleResult);
    console.log('deleting temporary records. {!reportId}');
}
I've also tried the different syntax for JS Remoting like this:
[removed] = function() {
    // delete the temporary records.
    MyController.deleteTemporaryRecords('{!reportId}',handleResult);
    console.log('deleting temporary records. {!reportId}');
}
I've also tried using an actionFunction inside the apex:Form

    

[removed] = function(){
    deleteTemporaryRecords();
};
I also tried calling a @future method from my controller method so that the delete happens asynchronously, but that hasn't worked either.

Has anyone been able to successfully run a controller method during [removed] or [removed] events?

Your answer

1 Answer

More Salesforce discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Salesforce Blogs

Guides, tips and career advice on Salesforce from JanBask experts.