You need to sign in to do that
Don't have an account?
rohitr
Pass Value from Standard controller Constructor to global static method
My Controller Code:
global with sharing class CustomHighlightsPanelController {
public Account accountInstance;
global static String accountName {get; set;}
global static String primeTabValue {get; set;}
public CustomHighlightsPanelController(ApexPages.StandardController controller) {
accountInstance = (Account)controller.getRecord();
accountName = accountInstance.Id;
System.debug('_______##############______'+accountName);
}
public PageReference FetchTabId() {
return null;
}
@RemoteAction
global static Premium_Payment__c[] loadPremiumPaidRecs() {
List<Premium_Payment__c> premiumPaymentList = new List<Premium_Payment__c>();
premiumPaymentList = [SELECT Id, Customer_Name__c, Paid_Premium__c, Policy__c, Premium_Paid_Date__c,Premium_Paid_Month_Year__c
FROM Premium_Payment__c WHERE Customer_Name__c =: accountName];
return premiumPaymentList;
}
}
accountName inside the SOQL query is getting null. but the variable accountName in the system.debug line gives a value.
How can i pass the contructor variable to the global static method which is defined as @RemoteAction.
global with sharing class CustomHighlightsPanelController {
public Account accountInstance;
global static String accountName {get; set;}
global static String primeTabValue {get; set;}
public CustomHighlightsPanelController(ApexPages.StandardController controller) {
accountInstance = (Account)controller.getRecord();
accountName = accountInstance.Id;
System.debug('_______##############______'+accountName);
}
public PageReference FetchTabId() {
return null;
}
@RemoteAction
global static Premium_Payment__c[] loadPremiumPaidRecs() {
List<Premium_Payment__c> premiumPaymentList = new List<Premium_Payment__c>();
premiumPaymentList = [SELECT Id, Customer_Name__c, Paid_Premium__c, Policy__c, Premium_Paid_Date__c,Premium_Paid_Month_Year__c
FROM Premium_Payment__c WHERE Customer_Name__c =: accountName];
return premiumPaymentList;
}
}
accountName inside the SOQL query is getting null. but the variable accountName in the system.debug line gives a value.
How can i pass the contructor variable to the global static method which is defined as @RemoteAction.
function initCharts() {
CustomHighlightPanelController.loadPremiumPaidRecs('{!accountName}',
function(result, event){
....... etc
You'll need to change the controller method to accept this parameter also:
global static Premium_Payment__c[] loadPremiumPaidRecs(String accName) {
List<Premium_Payment__c> premiumPaymentList = new List<Premium_Payment__c>();
premiumPaymentList = [SELECT Id, Customer_Name__c, Paid_Premium__c, Policy__c, Premium_Paid_Date__c,Premium_Paid_Month_Year__c
FROM Premium_Payment__c WHERE Customer_Name__c =: accName];
return premiumPaymentList;
}
You may also need to change the accountName to a regular public property in the class, rather than a global static, but it might work as it is.
All Answers
Therefore you'll need to alter your Visualforce page to include the accountName from the controller in the remote method call.
My javascript is defined like shown below:
<script type="text/javascript">
google.load('visualization', '1.0', {'packages':['corechart']});
google.setOnLoadCallback(initCharts);
function initCharts() {
CustomHighlightPanelController.loadPremiumPaidRecs(
function(result, event){
var visualization = new google.visualization.PieChart(document.getElementById('PremiumPaidChart'));
var data = new google.visualization.DataTable();
data.addColumn('string', 'Month & Year');
data.addColumn('number', 'Amount');
for(var i =0; i<result.length;i++){
var r = result[i];
data.addRow([r.Premium_Paid_Month_Year__c, r.Paid_Premium__c]);
}
visualization.draw(data, {legend : {position: 'none', textStyle: {color: 'black', fontSize: 10}}, width:window.innerWidth,vAxis:{title: 'Amount', textStyle:{fontSize: 10}},hAxis:{title: 'Month & Year', textStyle:{fontSize: 10},showTextEvery:1,slantedText:false}});
}, {escape:true});
}
</script>
Please help me with the code.
Thanks in Advance.
function initCharts() {
CustomHighlightPanelController.loadPremiumPaidRecs('{!accountName}',
function(result, event){
....... etc
You'll need to change the controller method to accept this parameter also:
global static Premium_Payment__c[] loadPremiumPaidRecs(String accName) {
List<Premium_Payment__c> premiumPaymentList = new List<Premium_Payment__c>();
premiumPaymentList = [SELECT Id, Customer_Name__c, Paid_Premium__c, Policy__c, Premium_Paid_Date__c,Premium_Paid_Month_Year__c
FROM Premium_Payment__c WHERE Customer_Name__c =: accName];
return premiumPaymentList;
}
You may also need to change the accountName to a regular public property in the class, rather than a global static, but it might work as it is.
<script type="text/javascript">
Visualforce.remoting.timeout = 120000; // Set timeout at page level
var theLastName = document.getElementById('Participant__c.Last_Name__c').value;
function getRemoteAccount() {
// This remoting call will use the page's timeout value
Visualforce.remoting.Manager.invokeAction(
'{!$RemoteAction.Participant_Surgeries_controller.getSurgeries}',
theLastName,
handleResult
);
}
</script>
Hard coded last name returns the set but including variables get SOQL or other error:
@RemoteAction
global static List<Surgery__c> getSurgeries(){
List<Surgery__c> surgeries = new List<Surgery__c>();
try{
surgeries = [Select Name, Surgery__c.Scheduled_Date__c from Surgery__c
Where Surgeon__r.Last_Name__c ='huang' ]; //theLastName or Last_Name__c is what I want to pass here
} catch(DMLException e){
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, 'Error creating new page.'));
return null;
}
return surgeries;
}