You need to sign in to do that
Don't have an account?
rohitr
Pass a variable from controller method to Visualforce
Hi All,
Please let me know how to pass a variable defined in a method inside a controller to the VF page.
@RemoteAction global static AggregateResult[] loadOpportunity() { closingToday = 0; Date mydate = System.today(); Date mydate1 = System.today().addDays(-45); Date mydate2 = System.today().addDays(45); List<AggregateResult> OppList = new List<AggregateResult>(); OppList = [SELECT StageName, CloseDate, Sum(Amount) amountSum FROM Opportunity WHERE OwnerId =: OwnerId AND StageName =: StageList AND CloseDate >: myDate1 AND CloseDate <: myDate2 GROUP BY StageName, CloseDate]; for(AggregateResult opp :OppList) { if(opp.get('CloseDate') = myDate) { closingToday = closingToday +1; } } }
I want to use this closingToday variable to use on the VF page.
<p> Numner of Opportunity Closing Today is: {!ClosingToday}</p>
How can i declare this variable in the controller?
I'm using google charting for which @RemoteAction annotation is used.
Any help would be appreciated.
Thanks in Advance
Hi,
Try this
In controller write like this
public Date ClosingToday{get;set;}
If this post solves your problem kindly mark it as solution. if this post is helpful please throw Kudos.
Thanks
All Answers
Hi,
Try this
In controller write like this
public Date ClosingToday{get;set;}
If this post solves your problem kindly mark it as solution. if this post is helpful please throw Kudos.
Thanks
Thanks for looking into.
But this was throwing an error.
I hope this declaration is only for variables used in constructor method.
I am not using a contructor.
Regards
No, It will also work even if you not use this in constructor.
Please mention the error which is coming.
If this post is helpful please give kudos.
Thanks
I'm not getting any error. On the page the variable value is not displayed.
Check if any value is present in that variable or not. Also print the value using System.debug and check in debug what value is coming for that variable.
If this post solves your problem kindly mark it as solution. if this post is helpful please throw Kudos.
Thanks
Am sorry..
i declared the variable two times. outside the method as you mentioned and inside the method. So it was taking it up as new variable.
Thanks for helping souvik9086.
Yes, if you declare variable two times. the latest one will become populated.
Thanks