You need to sign in to do that
Don't have an account?
Can anyone help me to pass values from VF page to Controller and return a results.
I am trying to create a VF page with the search fields. when we click on Search Interaction Button. results should show.
please refer to the below code and correct me
/** VF Code */
<apex:page standardController="Interaction__c" extensions="InteractionClass" docType="html-5.0" id="Page">
<apex:form id="form">
<apex:actionFunction name="savedata" action="{!sendData}" reRender="resultPanel" status="myStatus">
<apex:param name="firstParam" assignTo="{!selectedStatus}" value="" />
<apex:param name="secondParam" assignTo="{!assignedID}" value="" />
</apex:actionFunction>
<apex:sectionHeader title="Enter Details to Search Interaction"/>
<apex:pageblock id="pb">
<apex:pageblocksection columns="1" id="pbs">
<apex:commandButton action="{!URLFOR($Action.Interaction__C.New)}" value="Create New Interaction" />
<apex:input label="Interaction ID" value="{!interactionID}"/>
<apex:inputfield value="{!Interaction__c.Interaction_Date_Time__c}" id="date"/>
<apex:inputField value="{!Interaction__c.Status__c}" id="status"/>
<apex:inputField value="{!Interaction__c.Assigned_Group__c}" id="GroupID"/>
<apex:inputField value="{!Interaction__c.Interaction_Assigned_To__c}" id="AssignedTo"/>
<apex:commandButton action="{!searchInteraction}" value="Search Interaction" onclick="getValues();"/>
</apex:pageblocksection>
<apex:pageBlockTable value="{!Interactions}" var="i" rendered="{!displayResults}">
<apex:column headerValue="Action" width="55">
<apex:commandLink value=" Edit " action="{!URLFOR($Action.Interaction__C.Edit,i.id)}"/> |
<apex:commandLink value=" Del" action="{!URLFOR($Action.Interaction__C.Delete,i.id)}"/>
</apex:column>
<apex:column headerValue="Interaction ID" >
<apex:commandLink value="{!i.name}" action="/{!i.id}"/>
</apex:column>
<apex:column value="{!i.Interaction_Date_Time__c}"/>
<apex:column value="{!i.Status__c}"/>
<apex:column value="{!i.Assigned_Group__c}"/>
<apex:column value="{!i.Interaction_Assigned_To__c}"/>
</apex:pageBlockTable>
</apex:pageblock>
</apex:form>
<script type="text/javascript">
function getValues()
{
var statusval=document.getElementById('Page:form:pb:pbs:status').value;
// alert(statusval);
var ag=document.getElementById('Page:form:pb:pbs:GroupID').value;
//alert(ag);
var ap=document.getElementById('Page:form:pb:pbs:AssignedTo').value;
//alert(ap);
var dt=document.getElementById('Page:form:pb:pbs:date').value;
// alert(dt);
savedata(statusval,ap);
}
</script>
</apex:page>
/** Controller Code **/
public class InteractionClass {
Public String interactionID {get; set;}
Public Datetime interactiondttm {get; set;}
Public String selectedStatus {get; set;}
Public String assignedID {get; set;}
Public Boolean displayResults {get; set;}
public String result{get;set;}
Public List<Provider_Group__C> assignedGroupTemp=new List<Provider_Group__C>();
Public List<Interaction__C> searchInteractions{get; set;}
Public date intdate {get; set;}
public InteractionClass(ApexPages.StandardController stdController) {
displayResults=false;
}
Public PageReference CreateInteraction(){
PageReference pr = new PageReference('/apex/CreateInteractionPage');
return pr;
}
public string sendData(){
result='You have entered : 1 - '+selectedStatus+' 2 -'+assignedId;
return result;
}
Public List<Interaction__C> getInteractions(){
searchInteractions=[select ID,Name,Interaction_Date_Time__c,Status__C,Assigned_Group__c,Interaction_Assigned_To__c
from Interaction__C
WHERE Status__C =:selectedStatus
ORDER BY Name ASC limit 25];
return searchInteractions;
}
Public PageReference searchInteraction(){
displayResults=true;
getInteractions();
return null;
}
}
Some Points you should note before going further:
1.To pass the value form Visual page to Controller You can pass it using
<apex:Param assignTo="{!yourControllervariable}" value="{!yourvalue}"/>
2.And , I've Gone Through your code you are using standard controller for you
custom object and getting all details of your Interaction__c object.
3.You can just Initialize the Custom Object varibale in controller and get the value
from the visual page
(i.e.) Inside controller:
{
Interaction__c interaction_varibale{get;set;}
public InteractionClass
{
interaction_varibale=new Interaction();
//initializing the variable
}
}
Inside Visual Page
{
<apex:pageblocksection columns="1" id="pbs">
<apex:commandButton action="{!URLFOR($Action.Interaction__C.New)}" value="Create New Interaction" />
<apex:input label="Interaction ID" value="{!interactionID}"/>
<apex:inputfield value="{!interaction_varibale.Interaction_Date_Time__c}" id="date"/>
<apex:inputField value="{!interaction_varibale.Status__c}" id="status"/>
<apex:inputField value="{!interaction_varibale.Assigned_Group__c}" id="GroupID"/>
<apex:inputField value="{!interaction_varibale.Interaction_Assigned_To__c}" id="AssignedTo"/>
<apex:commandButton action="{!searchInteraction}" value="Search Interaction" />
</apex:pageblocksection>
}
Note-->{ Your interaction_varibale will have all the value, and you can insert or you can print it}
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha
www.kdeepali.com