You need to sign in to do that
Don't have an account?

How to preserve variable state between two Visualforce Javascript Remoting requests
Hi All,
Is there any way to preserve variable state between two successive Visualforce Javascript Remoting requests?
For eg:-
on debugging I am getting null value for myOpportunities.currentOpportunities on getClosedOpportunityCount() function.
Is there any way to do this?
Is there any way to preserve variable state between two successive Visualforce Javascript Remoting requests?
For eg:-
class myOpportunities{ public static list<opportunity> currentOpportunities; @RemoteAction public static string getOpportunities(){ myOpportunities.currentOpportunities = [SELECT id, Name, status FROM opportunity WHERE CreatedDate = LAST MONTH]; JSONGenerator gen = JSON.createGenerator(true); gen.writeStartObject(); gen.writeObjectField('data', myOppertunities.currentOppertunities); gen.writeEndObject(); jsonData = gen.getAsString(); return jsonData; } @RemoteAction public static integer getClosedOpportunityCount(){ integer count = 0; for(opportunity opp: myOpportunities.currentOpportunities){ if(opp.ststus == 'Closed'){ count++; } } return count; } }getOpportunities functiong(); called on page load & getClosedOpportunityCount(); called on a button click.
on debugging I am getting null value for myOpportunities.currentOpportunities on getClosedOpportunityCount() function.
Is there any way to do this?
If you want to set up values in the controller that are available across requests, you'll have to use regular Visualforce and maintain the state of the controller in the view state, with all its attendent effects on performance etc.
All Answers
But from the way the logic is built, I feel you dont really need a 2nd remote action method to get the closed count, as you already have the opportunities available to you in your VF Page, can you not build the count in the Javascript itself?
Actually this is sample scenario, I try to explain it simple as possible.
If you want to set up values in the controller that are available across requests, you'll have to use regular Visualforce and maintain the state of the controller in the view state, with all its attendent effects on performance etc.