+ Start a Discussion
rohitrrohitr 

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

Best Answer chosen by Admin (Salesforce Developers) 
souvik9086souvik9086

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

souvik9086souvik9086

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

This was selected as the best answer
rohitrrohitr

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

 

 

souvik9086souvik9086

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

rohitrrohitr

I'm not getting any error. On the page the variable value is not displayed.

souvik9086souvik9086

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

rohitrrohitr

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.

souvik9086souvik9086

Yes, if you declare variable two times. the latest one will become populated.

 

Thanks