1

I am calling the controller method from action function but it is not getting called from the action function.

Please review the below code.

Visualforce Page

<apex:outputPanel id="hhPageMessage" layout="block" rendered="{!message != null && message != ''}" styleClass="{!'page-msg '+severity+'-msg'}">
                                    <apex:outputText escape="false" value="{!message}" />
                                </apex:outputPanel>

<div class="col-sm-6">
                                                <button type="button" class="btn status btn-secondary btn-apply" onclick="openCancelPopup(); return false;">Cancel</button>
                                            </div>

<div id="cancelPopup" class="modal-cancel">
                                <div class="modal-content-cancel text-center">
                                    <span class="close" onclick="closeCancelPopup();">&times;</span>
                                    <h4 class="cancel-h4">Are you sure you want to cancel?</h4>
                                    <label class="cancel-label">You cannot continue the same application if you cancel.</label>
                                    <div class="row">
                                        <div class="col-sm-6">
                                            <button type="button" class="btn-secondary cancel" onclick="cancelApp();return false;">Cancel Application</button>
                                            <apex:actionFunction name="cancelInfoApp" oncomplete="callMethod()" action="{!cancelApplication}"  reRender=“cancelInfoApp,hhPageMessage”/>
                                        </div>
                                        <div class="col-sm-6">
                                            <button type="button" class="btn-secondary continue-app" onclick="closeCancelPopup()">Continue Application</button>
                                        </div>
                                    </div>                                
                                </div>
                            </div>
<script>
function cancelApp(){
                console.log('Cancelled Called');
                cancelInfoApp();
            } 
</script>

Apex Class

public PageReference cancelApplication(){
        severity = 'error';
        try{
            app.Application_Status__c = 'Cancelled';
            app.Cancellation_Date__c = System.today();
            update app;

            ApplicationModel am = new ApplicationModel(app.Id);
            am.evalTransitionAct();
            am.updateApplicationBatchSafe();

            VK 5262020 Email Notification Upon Cancelled Application (EVORP2NJ-140).
            EV_ApplicationController.sendCancellationEmail(clientRec);
            System.debug('Application Cancelled called');
            PageReference pr = new PageReference('EV_MyDashboard');
            return pr;
        }catch(Exception e){
            new ExceptionLogger('EV_IncomeInfoController', 'cancelApplication', app.Id, null, e).createExceptionRecord();
            message = e.getTypeName()+' '+ e.getMessage()+' = '+e.getStackTraceString();
            System.debug('Exception due to====='+e.getMessage()+e.getLineNumber());
            return null;
        }
        
    }  
1

The action function isn't necessary here, you can just:

<apex:commandButton 
  class="btn-secondary cancel" 
  oncomplete="callMethod()" 
  action="{!actincelApplication}" 
  reRender=“cancelInfoApp,hhPageMessage”>
    Cancel Application
</apex:commandButton>

Your original method should work, too, but without an error message, it's difficult to tell why it's not working. Is your apex:actionFunction between an apex:form? That could cause problems if it's not. Context is important here, and we don't have enough of it.

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.