I have a visualForce page and an apex controller. I need to get a date value from my visualForce page into my Apex Controller (this is done already) and then pass this value into my SOQL query. My SOQL query runs fine when I put an actual date value in, but when I use the variable created before it says can't find variable named x.
I'm certain this is a general programming mistake, this is only my second week using code not clicks!
Let me know if you want to see the VF page too.
**Apex Controller***
global with sharing class GoogleChartsController2 {
Opportunity o = new Opportunity();
public Opportunity getProxyObject() {
return o;
}
/**
Loads all Opportunities and then filters
*/
@RemoteAction
global static Opportunity[] loadOpps() {
return [select Id, Name, ExpectedRevenue, LeadSource, DaysToStartDate__c, Probability, CloseDate, Amount from Opportunity WHERE CloseDate = :o.CloseDate ];
}
}
Section from VisualForce Page *
<apex:page controller="GoogleChartsController2" sidebar="false">
<!-- Google API inclusion -->
<apex:includescript id="a" value="https://www.google.com/jsapi">
<apex:sectionheader title="Google Charts + Javascript Remoting" subtitle="Demoing - Opportunities by Exepected Revenue">
<!-- Google Charts will be drawn in this DIV -->
<div id="chartBlock" style="width: 900px; height: 500px;">>
<script type="text/javascript">
// Load the Visualization API and the piechart package.
google.load('visualization', '1.0', {'packages':['corechart']});
// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(initCharts);
function initCharts() {
// Following the usual Remoting syntax
// [<namespace>.]<controller>.<method>([params...,] <callbackFunction>(result, event) {...}
// controller : GoogleChartsController
// method : loadOpps
GoogleChartsController2.loadOpps(
function(result, event){
// load Column chart
var visualization = new google.visualization.BubbleChart(document.getElementById('chartBlock'));
// Prepare table model for chart with columns
var data = new google.visualization.DataTable();
data.addColumn('string', 'Opportunity');
data.addColumn('number', 'Days To Contract Start');
data.addColumn('number', 'Probability (%)');
data.addColumn('string', 'Lead Source');
data.addColumn('number', 'Amount');
// add rows from the remoting results
for(var i =0; i<result.length;i++){
var r = result[i];
data.addRow([r.Name, r.DaysToStartDate__c, r.Probability, r.LeadSource, r.Amount]);
}
// all done, lets draw the chart with some options to make it look nice.
visualization.draw(data, {
legend : {position: 'right', textStyle: {color: 'black', fontSize: 10}},
width:window.innerWidth,
length:window.innerLength,
vAxis:{title: 'Probability', textStyle:{fontSize: 10}, minValue: 0, maxValue: 100},
hAxis:{title: 'Days Until Close' , textStyle:{fontSize: 10},
chartArea: {width: '50%', height: '75%'},
sizeAxis: {minSize: 150, minValue: 150},
showTextEvery:1,slantedText:false}})
},
{escape:true});
}
</script>
</div></apex:sectionheader></apex:includescript>
<apex:form >
<apex:outputlabel value="Enter your name here"/>
<apex:inputField value="{!proxyObject.closeDate}"/>
<apex:actionsupport event="onclick" rerender="display" />
<apex:outputpanel id="display">
<apex:outputtext value="The date entered is {!proxyObject.closeDate}"/>
</apex:outputpanel>
</apex:form>
</apex:page>
o.CloseDate
on the VF page somewhere? It doesn't look like you're querying/populating it anywhere in this code snippet, so your query is going to be looking for Opportunity records with aCloseDate
ofnull
. – JCD