Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in Salesforce by (11.9k points)

I have a commandButton in a visualforce component. The expected behavior is that the controller method would be called. The page is refreshed, but the method registered in the commandButton {!performUnlinkContact} is not called. The strange thing is that if I put the button on the base visualforce page, it calls the controller method as expected - but when in a component, it does not.

Here is my component:

<apex:component >

    <apex:attribute name="rk" description="RK Base Contact Data"  type="Object" required="true"/>

    <div class="unlinkBox">

        <div class="unlinkHeader">

            <div class="unlinkHeaderLeft">Wrong Contact?</div>

            <div class="unlinkHeaderRight"><a href=""  onclick="return hideUnlinkPanel()"><apex:image style="cursor: pointer;" value="{!$Resource.x}" alt="Close Panel" /></a></div>

        </div>

        <div class="unlinkBody">

            <div class="unlinkBodyLeft">

                Click Yes if the Contact displayed is incorrect.<br/><br/>You will be given the opportunity to link to a different Contact.

            </div>

            <div class="unlinkBodyRight">

                <apex:outputpanel id="callMethod">

                    <apex:commandbutton value="Yes, this is the wrong contact" action="{!performUnlinkContact}" rerender="" status="myDisplayStatus" />&nbsp;&nbsp;&nbsp;&nbsp;<a onclick="return hideUnlinkPanel()" style="color:blue;cursor:pointer;text-decoration:underline">No</a>

                </apex:outputpanel>

                <apex:actionStatus id="myDisplayStatus"  startText="(performing Contact Unlink...)"  stopText=""/>

            </div>

        </div>

    </div>

</apex:component>

and here is the method in the controller extension:

public PageReference performUnlinkContact() {
     System.debug('==================================!!performUnlink');
    if (this.thisLead.rkContactId__c != 0) {
        this.thisLead.rkContactId__c = 0;
        update this.thisLead;
    }
    return null;
}
I'm sure I must be doing something wrong since I am new to salesforce and still learning, but I am unable to find any related issues when I search on how to resolve this issue. Thanks in advance for the help.

1 Answer

0 votes
by (32.1k points)
edited by

To resolve this issue, you need to add an actionFunction to the base Page, then just call this function in the component via a button's onclick event:

Code in base page:

    <apex:actionFunction name="doUnlink" action="{!performUnlinkContact}" rerender="refresh" status="myStatus"/>

Code to call function in the component:

    <input type="button" value="Yes, this is the wrong contact" onclick="doUnlink();" />

This method seems to work well so far.

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94.7k users

Browse Categories

...