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
EmilyCobbEmilyCobb 

JavaScript, VF, and Apex - how to maintain a variable

I have an interesting timeline of actions and I'm not sure how/if this will work.
I have a VF page that loads JavaScript. The JavaScript has an ID for a task record. From the JavaScript I am calling a class with the ID: 
 
global with sharing class JSControlsController
 {

  public static Id taskId;

   @RemoteAction
    global static void setTaskId(String inputTaskId)
    { 
    if (taskId != null && taskId != ''){
      taskId = inputTaskId;
     } 
    }


The catch is that I don't have a use for this ID until a user opens a Case and the Case Trigger (before or after insert) fires. This may or may not happen. If it does happen, I want to see if the taskID is set for this user. I can null out the taskID when the user's activity that I'm logging ends. But in the meantime, will this value stay set? Will having multiple users also performing the same actions overwrite the taskID value, or will each user's instance of the class remain? 
Thanks

 
sandeep@Salesforcesandeep@Salesforce
Emily,

In case of multiple users performing same action overwrite taskID onky if they are comiting it to database until that Id will be in their instance of class.

Thanks
Sandeep Singhal
http://www.codespokes.com/
 
EmilyCobbEmilyCobb
Thanks Sandeep. I actually did a quick test and it's not retaining it. These are going to happen in two separate transactions. I thought about using Session Cache but the use case doesn't quite fit (it would be a frequently changing variable) - any other ideas?