You need to sign in to do that
Don't have an account?
mitch_miller
Pass Value from Standard controller to global static methed
mitch_miller
This pattern for the controller seems to work for others but I am unable to access any variables in the controller to pass thequery as an arguement - I assume because it is static:
global with sharing class Participant_Surgeries_controller {
public String [] participants{get;set;}
private final Participant__c participant;
global Static String lastName;
ApexPages.StandardController m_controller;
public Participant_Surgeries_controller(ApexPages.StandardController controller) {
m_controller = controller;
this.participant = (Participant__c) controller.getRecord();
}
@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 = :this.participant.Last_Name__c ]; //variations with 'this.participant' or local variable are not in scope
// but a hard coded value works fine.
} catch(DMLException e){
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, 'Error creating new page.'));
return null;
}
return surgeries;
}
}
This pattern for the controller seems to work for others but I am unable to access any variables in the controller to pass thequery as an arguement - I assume because it is static:
global with sharing class Participant_Surgeries_controller {
public String [] participants{get;set;}
private final Participant__c participant;
global Static String lastName;
ApexPages.StandardController m_controller;
public Participant_Surgeries_controller(ApexPages.StandardController controller) {
m_controller = controller;
this.participant = (Participant__c) controller.getRecord();
}
@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 = :this.participant.Last_Name__c ]; //variations with 'this.participant' or local variable are not in scope
// but a hard coded value works fine.
} catch(DMLException e){
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, 'Error creating new page.'));
return null;
}
return surgeries;
}
}
You'll need to pass the participant last name as a parameter to the remote method from the page if you want to access it..
global with sharing class Participant_Surgeries_controller {
public String [] participants{get;set;}
private final Participant__c participant;
global Static String staticLastName;
ApexPages.StandardController m_controller;
public Participant_Surgeries_controller(ApexPages.StandardController controller) {
m_controller = controller;
this.participant = (Participant__c) controller.getRecord();
}
@RemoteAction
global static List<Surgery__c> getSurgeries(String lastName){
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 = :lastName]; //query works in Developer Console & method works when string 'smith' used instead of :lastName
} catch(DMLException e){
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, 'Error creating new page.'));
return null;
}
return surgeries;
}
}
<apex:page standardController="Participant__c" extensions="Participant_Surgeries_controller" sidebar="false" showHeader="false">
<Head>
</Head>
<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
);
}
//dummy function
function handleResult(result, event){}
</script>
<apex:form >
<apex:pageBlock >
<apex:repeat value="{!surgeries}" var="surgery">
<apex:outputPanel >
<apex:outputLink value="{!surgery.id}" >{!surgery.name} - {!surgery.Scheduled_Date__c}</apex:outputLink>
<br/>
</apex:outputPanel>
</apex:repeat>
</apex:pageBlock>
</apex:form>
Content cannot be displayed: Unknown property 'Participant__cStandardController.surgeries'
@RemoteAction
global static List<Surgery__c> getSurgeries(String lastName){
List<Surgery__c> surgeries = new List<Surgery__c>();
try{
surgeries = [Select Name, Surgery__c.Scheduled_Date__c from Surgery__c
Where Surgeon_Last_Name_2__c = :lastName];
} catch(DMLException e){
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, 'Error creating new page.'));
return null;
}
return surgeries;
}
but there is no getSurgeries method that can be used in this way. When you use remoting, its up to you to parse the results and manipulate the DOM.
http://www.salesforce.com/us/developer/docs/pages/Content/pages_js_remoting_example.htm
Also, the VisualForce snippet that you posted works fine when I replace the :lastName variable with a hard coded string containing an actual last name, e.g. 'smith'.
I am not sure why the error complains about Participant, which is a child object of Surgery, when a string is not used, but I suspect that my problem might be there:
Content cannot be displayed: Unknown property 'Participant__cStandardController.surgeries'
I'm afraid that you can't use standard components on methods that are annotated as @RemoteAction.