0

I am trying to call a method on completion of action on buttonclick

Button Code:

<apex:commandButton action="{!save}" 
    id="saveButton" 
    status="actStatusId" 
    title="{!$Label.ahm__Save}" 
    value="{!$Label.ahm__Save}" 
    reRender="cREditPanel,pageMessagesPanel,pageMessages,campaignCRSection,eventCRSection"  
    oncomplete="completecallout();" 
    styleclass="ladda-button"/>

Controller: below method should be executed on complete of action in save button.

public void completecallout(){
    doCallout(selectedRecordId);
    system.debug('callout++'+selectedRecordId); 
}

on completion of save button action I need to execute the above method code.

1

Oncomplete attribute accepts a JavaScript function.

You can use action function or JavaScript remoting if you want to call Apex function from JavaScript.

Visualforce code:

<apex:commandButton action="{!save}" 
    id="saveButton" 
    status="actStatusId" 
    title="{!$Label.ahm__Save}" 
    value="{!$Label.ahm__Save}" 
    reRender="cREditPanel,pageMessagesPanel,pageMessages,campaignCRSection,eventCRSection"  
    oncomplete="callCompleteCallout();" 
    styleclass="ladda-button"/>

<apex:actionFunction 
    name="callCompleteCallout" 
    action="{!completecallout}" 
    rerender="pageMessagesPanel"/>

Apex code:

public void completecallout(){
    doCallout(selectedRecordId);
    system.debug('callout++'+selectedRecordId); 
}
0

You need actionfucntion here. Call onCompleteHandler javascript method on onComplete of your commandbutton.

<script>
    function onCompleteHandler() {
         completecallout();
    }
</script>

<apex:commandButton action="{!save}" id="saveButton" status="actStatusId" title="{!$Label.ahm__Save}" value="{!$Label.ahm__Save}" reRender="cREditPanel,pageMessagesPanel,pageMessages,campaignCRSection,eventCRSection"  oncomplete="onCompleteHandler();" styleclass="ladda-button"/>

<apex:actionfunction name="completecallout" action="{!completecallout}"/>

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.