You need to sign in to do that
Don't have an account?

how to call apex method from JavaScript in VF
Hi All,
Please help me with below request.
I want to calll a apex method from my javaScript
<apex:page controller="ViewQAAMController">
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value="{!BadgeList}" var="data" align="center" styleClass="table table-striped" >
<apex:column headerValue="MyValues">
<apex:outputLink value="{!data['Week__c']}" onclick="openWindow()">{!data['Week__c']}</apex:outputLink>
</apex:column>
</apex:pageBlockTable>
<apex:actionFunction action="{!MyMethod}" name="myFunction" />
</apex:pageBlock>
</apex:form>
<script>
function openWindow(){
window.open('/apex/AddQAAMWeeklyPlanner');
MyFunction();
}
</script>
</apex:page>
Controller:
public class ViewQAAMController {
public PageReference MyMethod() {
System.debug('I am called ILU');
return null;
}
//public List<AggregateResult> BadgeList { get; set; }
public List<AggregateResult> BadgeList
{
get
{
List<AggregateResult> badges = [select Week__c, max(createddate) apple from QAAM_Weekly_Planner__c Max group by Week__c order by max(createddate) desc LIMIT 10];
return badges;
}
set;
}
}
I want to call Mymethod() from controller from Java Script.
Kindly help
Regards
Karthic Sankar V P
Please help me with below request.
I want to calll a apex method from my javaScript
<apex:page controller="ViewQAAMController">
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value="{!BadgeList}" var="data" align="center" styleClass="table table-striped" >
<apex:column headerValue="MyValues">
<apex:outputLink value="{!data['Week__c']}" onclick="openWindow()">{!data['Week__c']}</apex:outputLink>
</apex:column>
</apex:pageBlockTable>
<apex:actionFunction action="{!MyMethod}" name="myFunction" />
</apex:pageBlock>
</apex:form>
<script>
function openWindow(){
window.open('/apex/AddQAAMWeeklyPlanner');
MyFunction();
}
</script>
</apex:page>
Controller:
public class ViewQAAMController {
public PageReference MyMethod() {
System.debug('I am called ILU');
return null;
}
//public List<AggregateResult> BadgeList { get; set; }
public List<AggregateResult> BadgeList
{
get
{
List<AggregateResult> badges = [select Week__c, max(createddate) apple from QAAM_Weekly_Planner__c Max group by Week__c order by max(createddate) desc LIMIT 10];
return badges;
}
set;
}
}
I want to call Mymethod() from controller from Java Script.
Kindly help
Regards
Karthic Sankar V P
<apex:form id ="frm">
<apex:actionfunction name="callfromJS" action="{!controllerMethodName} reRender="frm"/>
</apex:form>
<script>
function JSmethodCallFromAnyAction()
{
callfromJS();
}
</apex:page>
All Answers
Your query is answered in the below blogs,
https://developer.salesforce.com/forums/?id=906F00000008zaMIAQ
https://salesforce.stackexchange.com/questions/117978/calling-an-apex-method-from-javascript
I hope you find the above information is helpful. If it does, please mark as Best Answer to help others too.
Thanks.
<apex:form id ="frm">
<apex:actionfunction name="callfromJS" action="{!controllerMethodName} reRender="frm"/>
</apex:form>
<script>
function JSmethodCallFromAnyAction()
{
callfromJS();
}
</apex:page>
Hi Kartik,
Use below sample code :
<apex:actionFunction action="{!method1}" name="callMethod1" rerender="formId" >
<apex:param assignTo="{!param1}" name="prmNm" value=""/>
</apex:actionFunction>
Apex Controller :
public String param1{get;set;}
Please mark it as best answer