0

I can't seem to get the commandbutton to call a method from my controller. There are no errors, nothing at all in the debug log. The method is just not called for some reason.

Apex:

String documentCategory {get;set;}
String documentType {get;set;}
String documentId {get;set;}

public void deleteDocument(){
    system.debug('VISUALFORCEPARAMS' +documentType + documentCategory + documentId);
    hardDeleteDocument(account.Business__c, account.Customer_Number__c, documentCategory, documentType, documentId);
}

Visualforce:

<apex:page id="mypage" controller="mycontroller">
      <apex:tabPanel >
        <apex:tab label="Search Documents" id="searchDoc">
          <apex:form >
            <apex:pageMessages />

            <!-- search inputs -->
            <apex:commandButton action="{!searchRecords}" value="Search"></apex:commandButton>

            <apex:pageBlock >
                <apex:pageBlockTable value="{!foundDocuments}" var="doc">
                    <apex:column headerValue="action">
                        <apex:commandButton value="View" />
                        <apex:commandButton value="Download" />
                        <apex:commandButton value="Delete" action="{!deleteDocument}" >
                            <apex:param value="{!doc.category}" name="docCategory" assignTo="{!documentCateogry}"></apex:param>
                            <apex:param value="{!doc.type}" name="docType" assignTo="{!documentType}"></apex:param>
                            <apex:param value="{!doc.fileId}" name="fileId" assignTo="{!documentId}"></apex:param>
                        </apex:commandButton>
                    </apex:column>
                    <!-- other columns -->
                </apex:pageBlockTable>
            </apex:pageBlock>
            </apex:form>
    </apex:tab>
    <!-- other tabs -->
</apex:tabPanel>
</apex:page>
3
  • 2
    add apex:pageMessages to your page and rerender it on button click. There could be a some client side validation.
    – Raul
    Commented Mar 24, 2017 at 14:09
  • Are you sure you're opening up the correct log? I took a very close pared down reproduction case and it's working for me. I get null values but the method is called. And the parameter passing works fine if I change commandButton to commandLink.
    – Adrian Larson
    Commented Mar 24, 2017 at 17:36
  • @AdrianLarson Its the log that appears right after I click the button so that should be the correct one. The system debug is not present inside this is why I assume that its not getting called. If it matters hardDeleteDocument is doing a callout. Commented Mar 24, 2017 at 17:47

3 Answers 3

0

I've figured out how to fix it. I've wrapped the apex:commandButton in apex:actionRegion and it worked.

<apex:actionRegion >
<apex:commandButton value="Delete" action="{!deleteDocument}" reRender="debugSection,documentsTable">
<apex:param value="{!doc.category}" name="docCategory" assignTo="{!documentCategory}"></apex:param>
<apex:param value="{!doc.type}" name="docType" assignTo="{!documentType}"></apex:param>
<apex:param value="{!doc.fileId}" name="fileId" assignTo="{!documentId}"></apex:param>
</apex:commandButton>
</apex:actionRegion>                                                    
0

Use apex:commandLink instead of apex:commandButton. Just add styleClass="btn".

-1

One thing you may want to try is adding a rerender onto your command button.

I don't know why, but I have had a TON of issues with functions not being called by buttons/actionFunctions, but work fine after adding a rerender onto the thing trying to run the function. have no explanation for it, but it seems to have an effect for some reason.

The rerender doesn't even need to be real, or point to a real Id. It can literally be rerender="dummy" (I haven't tested if you even need something inside the quotes, but I assume you would...).

5
  • 3
    reRender="" is sufficient if you don't care about the target.
    – sfdcfox
    Commented Mar 24, 2017 at 14:26
  • I've tried the reRender both with Id and without Id, still no errors popping up. Commented Mar 24, 2017 at 14:58
  • @KostadinStoev It's still not running the controller function? Hmm...any javascript errors in the console? Commented Mar 24, 2017 at 15:08
  • @Dominator_101 Still not running. Apex Messages is not showing any erros and the only errors in the console are these: sessionserver204.html:1 Unrecognized Content-Security-Policy directive 'reflected-xss'. sessionserver204.html:1 Unrecognized Content-Security-Policy directive 'referrer'. logo180.png Failed to load resource: the server responded with a status of 404 (Not Found) Commented Mar 24, 2017 at 15:13
  • Hmm...I get those errors on basically everything now, so I don't think those are causing the issue... Commented Mar 24, 2017 at 15:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .