function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sujin h ssujin h s 

action function not calling apex method

Hi All,

Can anyone let me know, why the action function is not calling apex method?
Vf page:
<apex:page standardController="Opportunity" extensions="displayAlert">
    <apex:form id="eg">
        <apex:actionFunction name="Actfun" action="{!UpdatePopupShown}" reRender="eg">
        </apex:actionFunction>
        <script>  
        if('{!Opportunity.Active_Opportunity__c}.checked' && '{!Opportunity.Popup_Shown__c}.unchecked')
        { 
            console.log("Loaded");
            alert("My custom message!");
            Actfun();
        }
        </script>      
    </apex:form>
</apex:page>

Controller:
public with sharing class displayAlert {
    ApexPages.StandardController controller;
    
    public displayAlert(ApexPages.StandardController controller) {
        this.controller = controller;
    }
    
    public void UpdatePopupShown() {
        system.debug('Called controller 1');
        Opportunity m = (Opportunity)controller.getRecord();
        if(m.Popup_Shown__c == false){
            m.Popup_Shown__c = true;
            system.debug('Called controller 2');
        }
        update m;
    }
}

My debug statements are not showing in logs & i'm not getting any error.

Thanks! ​​​​​​​
Vishwajeet kumarVishwajeet kumar
Hello,
Values from Salesforce database for fields would be returned as true/false.
Try modified script below : 

<script>
if('{!Opportunity.Active_Opportunity__c}'  == true && '{!Opportunity.Popup_Shown__c}' == false)
{
console.log("Loaded");
alert("My custom message!");
Actfun();
}
</script>


Thanks
sujin h ssujin h s

Hi Vishwajeet,

<script> is working fine

The action function is not calling "UpdatePopupShown" method from the extension controller(displayAlert).

Vishwajeet kumarVishwajeet kumar
Hello,
Yes, i think i got that and it is because it is not able to reach to actionFunction which is called in script, infering from code provided above.

Thanks