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

actionfunction not calling apex class method, please help me.
I created one actionfunction and its name is "callmymethod" when i click on the button , this method is not calling . please help.
<apex:page controller="createDynamicTableProcess" > <apex:form > <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <script> function calldata() { //alert("this is 2nd alert"); //callmymethod(); //alert("this is 3rd alert"); } window.setTimeout(callmymethod,2000); </script> <apex:actionfunction name="callmymethod" action="{!insertSubContactRecords}" id="idd1"/> <apex:pageblock title="All contacts" > <apex:repeat value="{!cons}" var="a" > <table border="1" width="300px;" > <tr> <td><apex:outputtext value="{!a.name}" /> <br/></td> <td><apex:outputtext value="{!a.phone}" /><br/></td> <td><apex:outputtext value="{!a.account.industry}" /><br/></td> <td><apex:commandbutton value="Add Row" id="one" onclick="calldata();"> <!-- <apex:param name="sending contact id" value="{!a.id}" assignto="{!contactid}" /> --> </apex:commandbutton> <br/><br/></td> </tr> </table> <apex:pageblocktable value="{!scw}" var="a" id="pbt1"> <apex:column ><apex:inputcheckbox value="{!a.flag}" /> </apex:column> <apex:column ><apex:inputtext value="{!a.name}" onchange="getrec(this.id)" id="v1"/> </apex:column> <apex:column ><apex:inputtext value="{!a.country}" id="v2"/> </apex:column> </apex:pageblocktable> <center><apex:commandbutton value="Save Checked Records" ><apex:param value="{!a.id}" assignto="{!SpecificContactRecordId}" /> </apex:commandbutton></center> </apex:repeat> </apex:pageblock> </apex:form> </apex:page>
public class createDynamicTableProcess { public list<contact> cons{set;get;} public string contactid {set;get;} public list<subcontactwrapper> scw{set;get;} public list<subcontactwrapper> scw2{set;get;} public string SpecificContactRecordId{set;get;} public createDynamicTableProcess () { scw=new list<subcontactwrapper>(); scw2=new list<subcontactwrapper>(); cons=new list<contact>(); list<string> accids=new list<string>(); for(account a1:[select id from account]) { accids.add(a1.id); } cons=[select id,name,phone,account.industry from contact where accountid in:accids limit 1]; } //constructor closed //method for button click for every contact. public void createRecordForSubContact() { subcontactwrapper s1=new subcontactwrapper(); scw.add(s1); } public void insertSubContactRecords() { list<subcontact__c> subc=new list<subcontact__c>(); for(subcontactwrapper s1: scw) { subcontact__c su=new subcontact__c(); su.name__c=s1.name; su.Country__c= s1.country; su.Contact__c=SpecificContactRecordId; subc.add(su); } insert subc; } public class subcontactwrapper { public boolean flag {set;get;} public string name{set;get;} public string country{Set;get;} } }
you don't have to use <script> to make this work: you create <apex:actionfunction tag, with name and action (some method from controller) and then do onclick(or other 'on' js parameter) to call your actionfunction.
You can also add parameters (if you have method with input values) with <apex:param....
Marek