[SalesForce] Command Button not calling action function

I am trying to call action function from command button but for some reason the method in the action function is not getting invoked at all. Can any one please point out what is the issue here.

<apex:commandButton id="songdbabc" onclick="Synchfromsongdb('{!wrapSong.seqObject.id}','Synch');" value="Synch from song db" />

<apex:actionFunction id="Synchfromsongdb" immediate="true" status="counterStatus" action="{!Synchsongmethod}" name="Synchfromsongdb">

Controller code

public PageReference Synchsongmethod()
{
        system.debug('synch song method is called');
        List<Cue_Sheet_Sequence__c> recordToVerify=new List<Cue_Sheet_Sequence__c>();
          Id seqIdsynch =Id.ValueOf(ApexPages.currentPage().getParameters().get('seqIdsynch'));
       system.debug('seqIdsynch'+sid);
        Cue_Sheet_Sequence__c newRecord =[Select id,Flagged_for_Delete__c,RapidCue_Delete_Timestamp__c, Verified__c from Cue_Sheet_Sequence__c where id=:seqIdsynch and Sequence_Order_No__c!=0];
       system.debug('newRecord '+newRecord );

               newRecord.Flagged_for_Delete__c=true;
        newRecord.RapidCue_Delete_Timestamp__c = system.now();
                recordToVerify.add(newrecord);

        update recordToVerify;
        return null;
 }

Best Answer

First thing, actionFunction is not needed here.

Secondly, be sure to use reRender attribute of the apex:commandButton.

<apex:commandButton id="songdbabc" value="Synch from song db" action="{!Synchsongmethod}" reRender="form">
    <apex:param name="seqIdsynch" value="{!wrapSong.seqObject.id}" assignTo="{!seqIdsynch}"/>
</apex:commandButton>

Thirdly, using assignTo attribute directly assigns the value to controller class' attribute

Fourthly, no need to type cast the String to Id when using in SOQL

Controller

public String seqIdsynch {get;set;}
public PageReference gotoContactDetailPage()
{
    System.debug('seqIdsynch=' + seqIdsynch);

    Cue_Sheet_Sequence__c newRecord =[Select id,Flagged_for_Delete__c,RapidCue_Delete_Timestamp__c, Verified__c from Cue_Sheet_Sequence__c 
    where id=:seqIdsynch 
    and Sequence_Order_No__c!=0];

    system.debug('newRecord '+newRecord );
    ...
    return null;
}
Related Topic