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 Mar 24 '17 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 Mar 24 '17 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. – Kostadin Stoev Mar 24 '17 at 17:47
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 Mar 24 '17 at 14:26
  • I've tried the reRender both with Id and without Id, still no errors popping up. – Kostadin Stoev Mar 24 '17 at 14:58
  • @KostadinStoev It's still not running the controller function? Hmm...any javascript errors in the console? – Dominator_101 Mar 24 '17 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) – Kostadin Stoev Mar 24 '17 at 15:13
  • Hmm...I get those errors on basically everything now, so I don't think those are causing the issue... – Dominator_101 Mar 24 '17 at 15:16

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.