function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
prasanth kumarprasanth kumar 

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=""></script>

function calldata()
//alert("this is 2nd alert");
//alert("this is 3rd alert");



<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="{!}" /> <br/></td>
<td><apex:outputtext value="{!}" /><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="{!}" assignto="{!contactid}" /> -->

</tr> </table> 
  <apex:pageblocktable value="{!scw}" var="a" id="pbt1">
            <apex:column ><apex:inputcheckbox value="{!a.flag}" /> </apex:column>
            <apex:column ><apex:inputtext value="{!}" onchange="getrec(" id="v1"/> </apex:column>
            <apex:column ><apex:inputtext value="{!}" id="v2"/> </apex:column>
<center><apex:commandbutton value="Save Checked Records"  ><apex:param value="{!}" assignto="{!SpecificContactRecordId}" />  </apex:commandbutton></center>

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])

       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();


public void insertSubContactRecords()
list<subcontact__c> subc=new list<subcontact__c>();
    for(subcontactwrapper s1: scw)
        subcontact__c su=new subcontact__c();;
        insert subc;
public class subcontactwrapper
public boolean flag {set;get;}
public string name{set;get;}
public string country{Set;get;}

Marek Kosar_Marek Kosar_

you don't have to use <script> to make this work:
<apex:actionfunction name="callmymethod" action="{!insertSubContactRecords}" id="idd1"/>
<apex:commandbutton value="Add Row"  id="one"  onclick="callmymethod();">
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....