1

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;
 }
  • why the actionFunction is needed here? You can directly call controller method and pass parameters – Santanu Boral Sep 16 '17 at 22:02
  • I tried that too still i was getting list has no rows error <apex:commandButton id="songdbabc" action="{!synchsongmethod}" value="Synch from song db"> <apex:param name="seqId" value="{!wrapSong.seqObject.id}" assignTo="{!sid}"/> </apex:commandbutton> controller method public id sid{get;set;}public PageReference Synchsongmethod(){List<Cue_Sheet_Sequence__c> recordToVerify=new List<Cue_Sheet_Sequence__c>(); Cue_Sheet_Sequence__c newRecord =[Select id,Flagged_for_Delete__c,RapidCue_Delete_Timestamp__c, Verified__c from Cue_Sheet_Sequence__c where id=:sid ]; – Natasha Sep 16 '17 at 22:06
  • The id returned is null , Can you please suggest what can be the problem here – Natasha Sep 16 '17 at 22:10
1

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;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.