I've tried to simplify my problem. I have a component like this:

<apex:component controller="GenericLookup">
    <apex:includeScript value="{!URLFOR($Resource.jQuery, 'jquery-1.8.2.min.js')}" />
    <script type="text/javascript">

        function openLookup(baseURL, width, modified, searchParam) {
            // Intercept Salesforce lookup
            // Pop custom lookup window

            // Detect popup closing
            var interval = window.setInterval(function() {
                console.log('Approaching the enemy base.');
                if (curPopupWindow == null || curPopupWindow.closed) {
                    console.log('I\'ve infiltrated the enemy base.');
                    try {
                        console.log('Hacking enemy systems.');
                        console.log('Data retrieved. End mission.');
                    catch (e) { console.log('We\'ve been had! Abort mission!'); }
           }, 1000);
    <apex:actionFunction action="{!ContactSelected}" name="contactSelected" reRender="" />
    <apex:outputLink onclick="openLookup(params);" />

And my controller is something like this:

public class GenericLookup {
    public void ContactSelected() {
        System.debug('Callback has this: ' + this);

When I debug the page I see all my console.log calls in the component. I do not see the System.debug in the controller. The browser (Chrome) developer tools have no errors.

Why is my ActionFunction doing nothing? How can I fix it?

  • Silly question on my part: Are you sure your debug flags in the Developer Console or Debug Logs setting set high enough to see your debug statements? I make this mistake about weekly, which is why I ask.
    – sfdcfox
    Feb 23 '15 at 21:06
  • 1
    Is there an<apex:form/> tag anywhere? <apex:actionFunction/> must be a child of that tag. Feb 23 '15 at 21:11
  • Didn't think of that as an issue. I don't think that's the case. The popup window calls System.debug, and I see that call just fine. And yes, I see all the javascript console.log calls.
    – ricksmt
    Feb 23 '15 at 21:12
  • 1
    Not sure if rerender="" will actually call the controller. Does the page refresh? If so, then try putting any text inside the rerender like rerender="nothing". Also do check that the debug log settings are at a minimum of DEBUG
    – Eric
    Feb 23 '15 at 21:16
  • I believe reRender="" works, though I actually have reRender="dummy" in my code. How can I check the log settings?
    – ricksmt
    Feb 23 '15 at 21:22

I think you should terminate the actionFunction tag after outputLink.

<apex:actionFunction action="{!ContactSelected}" name="contactSelected" reRender="">
    <apex:outputLink onclick="openLookup(params);" />

I thought I gave you enough information, but it turns out there was more to it. I also had this tag in the component backed by an ID property:

<apex:inputHidden id="__lkid" value="{!NewID}" />

Bad idea. NewID is initially null, but on postbacks this hidden input manages to set it to a blank ID. That setter triggers another property to get the object, but of course the object didn't exist, so things broke down. That's why none of my functions were firing: things had already failed in the properties' setup. I modified the property:

public ID NewID {
    set {
        try {
            value.getSObjectType();// This prevents the bad blank value
            NewID = value;
            if (Record.ID != NewID) Record = null;// This resets my other property
        catch (Exception e) {
            System.debug('ID is invalid: ' + value);

Sorry to waste your guys' time.

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.