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
SFDCDevQASFDCDevQA 

VisualForce Page not invoking class method

I have a very simple imbedded page and controller that is working in my dev org and has worked in previous sandbox and production orgs but for some reason is not working in the current sandbox I am working in.  Is there a setting somewhere that could be essentially disabling this?  It is on the page layout, the profiles have access to the page and the class, the debug shows that the page is being called and that it is looking at the class but the page is not invoking the MarkRead method from the class and the popups are not working.  Any suggestions or ideas would be GREATLY appreciated.
Thanks,
Amanda

Simple page to product popup alert
<apex:page standardController="Opportunity" extensions="OpportunityAlertExtension">
    <apex:form >
    <apex:actionFunction action="{!markread}" name="MarkRead"/>
    </apex:form>
<script type="text/javascript">
    if({!opp.Territory2id==null && opp.MNVAlert_Shown__c==False && (opp.Kind_HSS_STEM__c==null || opp.Kind_HSS_STEM__c == 'Other')}) {
        window.alert("This Opportunity is neither HSS or STEM. Please correct the Discipline and re-save");
        updateStatus(); 
    else if({!opp.Territory2id==null && opp.MNVAlert_Shown__c==False && (opp.Kind_HSS_STEM__c!=null || opp.Kind_HSS_STEM__c != 'Other')}) {
        window.alert("No territory found for this Opportunity. Please select the correct Owner and Territory manually");
        updateStatus(); 
    }

</script>
</apex:page>

Class called by VF Page
public class OpportunityAlertExtension {

    Public Opportunity opp      {get;set;}
    public OpportunityAlertExtension(ApexPages.StandardController controller) {
        ID oppID = controller.getID();
        System.debug('=== Opportunityid: ' + oppID);

        opp = [Select Id, Name, AccountId, MNVAlert_Shown__c, Kind_HSS_STEM__c, StageName, Territory2ID
            From Opportunity
            Where Id =:oppID ];
            System.debug('=== Opportunity: ' + opp);
    }
    

    public void markread() {
        Opportunity o = this.opp;
        o.MNVAlert_Shown__c = true;
        update o;
        System.debug('=== Opportunity updated: ' + o);
    }
}

Debug log

35.0 APEX_CODE,FINEST;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WORKFLOW,INFO 09:11:14.220 (220570453)|EXECUTION_STARTED 09:11:14.220 (220604813)|CODE_UNIT_STARTED|[EXTERNAL]|066L0000000EUbm|VF: /apex/Opportunity_Page_Alert 09:11:14.222 (222224285)|CODE_UNIT_STARTED|[EXTERNAL]|01pL0000000R08e|OpportunityAlertExtension <init> 09:11:14.222 (222241587)|SYSTEM_MODE_ENTER|true 09:11:14.222 (222852101)|HEAP_ALLOCATE|[72]|Bytes:3 09:11:14.222 (222914806)|HEAP_ALLOCATE|[77]|Bytes:152 09:11:14.222 (222936341)|HEAP_ALLOCATE|[342]|Bytes:408 09:11:14.222 (222958886)|HEAP_ALLOCATE|[355]|Bytes:408 09:11:14.222 (222980209)|HEAP_ALLOCATE|[467]|Bytes:48 09:11:14.223 (223020906)|HEAP_ALLOCATE|[139]|Bytes:6 09:11:14.223 (223054850)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:80 09:11:14.223 (223062706)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:6 09:11:14.223 (223066970)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:7 09:11:14.223 (223088249)|METHOD_ENTRY|[1]|01pL0000000R08e|OpportunityAlertExtension.OpportunityAlertExtension() 09:11:14.223 (223095331)|STATEMENT_EXECUTE|[1] 09:11:14.223 (223101201)|STATEMENT_EXECUTE|[1] 09:11:14.223 (223108960)|METHOD_EXIT|[1]|OpportunityAlertExtension 09:11:14.223 (223135430)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:8 09:11:14.223 (223159106)|VARIABLE_SCOPE_BEGIN|[4]|this|OpportunityAlertExtension|true|false 09:11:14.223 (223209207)|VARIABLE_ASSIGNMENT|[4]|this|{}|0x3d842d34 09:11:14.223 (223218151)|VARIABLE_SCOPE_BEGIN|[4]|controller|ApexPages.StandardController|true|false 09:11:14.223 (223350922)|VARIABLE_ASSIGNMENT|[4]|controller|"StandardController [null]"|0x187a6d2 09:11:14.223 (223363084)|STATEMENT_EXECUTE|[1] 09:11:14.223 (223366109)|STATEMENT_EXECUTE|[3] 09:11:14.223 (223380650)|HEAP_ALLOCATE|[5]|Bytes:6 09:11:14.223 (223416932)|VARIABLE_SCOPE_BEGIN|[2]|this|System.ApexBaseClass|true|false 09:11:14.223 (223438018)|VARIABLE_ASSIGNMENT|[2]|this|{}|0x3d842d34 09:11:14.223 (223453175)|STATEMENT_EXECUTE|[4] 09:11:14.223 (223456112)|STATEMENT_EXECUTE|[5] 09:11:14.223 (223546357)|HEAP_ALLOCATE|[5]|Bytes:15 09:11:14.223 (223583293)|HEAP_ALLOCATE|[5]|Bytes:4 09:11:14.223 (223590521)|VARIABLE_SCOPE_BEGIN|[5]|oppID|Id|false|false 09:11:14.223 (223653581)|VARIABLE_ASSIGNMENT|[5]|oppID|"006L0000008OEtxIAG" 09:11:14.223 (223661826)|STATEMENT_EXECUTE|[6] 09:11:14.223 (223667103)|HEAP_ALLOCATE|[6]|Bytes:19 09:11:14.223 (223731654)|HEAP_ALLOCATE|[6]|Bytes:18 09:11:14.223 (223759313)|HEAP_ALLOCATE|[6]|Bytes:37 09:11:14.223 (223784835)|HEAP_ALLOCATE|[50]|Bytes:5 09:11:14.223 (223807767)|HEAP_ALLOCATE|[56]|Bytes:5 09:11:14.223 (223819243)|HEAP_ALLOCATE|[64]|Bytes:7 09:11:14.223 (223865757)|USER_DEBUG|[6]|DEBUG|=== Opportunityid: 006L0000008OEtxIAG 09:11:14.223 (223876033)|STATEMENT_EXECUTE|[8] 09:11:14.223 (223880912)|HEAP_ALLOCATE|[8]|Bytes:125 09:11:14.223 (223895219)|HEAP_ALLOCATE|[8]|Bytes:4 09:11:14.223 (223908515)|HEAP_ALLOCATE|[8]|Bytes:7 09:11:14.224 (224347471)|SOQL_EXECUTE_BEGIN|[8]|Aggregations:0|SELECT Id, Name, AccountId, MNVAlert_Shown__c, Kind_HSS_STEM__c, StageName, Territory2ID FROM Opportunity WHERE Id = :tmpVar1 09:11:14.229 (229042000)|SOQL_EXECUTE_END|[8]|Rows:1 09:11:14.229 (229073034)|HEAP_ALLOCATE|[8]|Bytes:8 09:11:14.229 (229093831)|HEAP_ALLOCATE|[8]|Bytes:195 09:11:14.229 (229184597)|HEAP_ALLOCATE|[8]|Bytes:8 09:11:14.229 (229195789)|HEAP_ALLOCATE|[8]|Bytes:37 09:11:14.229 (229291244)|HEAP_ALLOCATE|[8]|Bytes:28 09:11:14.229 (229357008)|VARIABLE_ASSIGNMENT|[-1]|this|{}|0x3d842d34 09:11:14.229 (229394199)|VARIABLE_ASSIGNMENT|[-1]|value|{"s":1,"v":{"Id":"006L0000008OEtxIAG","Name":"Department1: QAI_Tes (24 more) ...","AccountId":"001L000000mWIJXIA4","MNVAlert_Shown__c":false,"StageName":"Prospecting","RecordTypeId":"012L0000000DKZ8IAO"}}|0x7f306188 09:11:14.229 (229419832)|VARIABLE_ASSIGNMENT|[3]|this.opp|{"s":1,"v":{"Id":"006L0000008OEtxIAG","Name":"Department1: QAI_Tes (24 more) ...","AccountId":"001L000000mWIJXIA4","MNVAlert_Shown__c":false,"StageName":"Prospecting","RecordTypeId":"012L0000000DKZ8IAO"}}|0x3d842d34 09:11:14.229 (229433864)|STATEMENT_EXECUTE|[11] 09:11:14.229 (229439674)|HEAP_ALLOCATE|[11]|Bytes:17 09:11:14.229 (229489763)|VARIABLE_ASSIGNMENT|[-1]|this|{"opp":"0x7f306188"}|0x3d842d34 09:11:14.229 (229572569)|HEAP_ALLOCATE|[11]|Bytes:197 09:11:14.229 (229597405)|HEAP_ALLOCATE|[11]|Bytes:214 09:11:14.229 (229611763)|USER_DEBUG|[11]|DEBUG|=== Opportunity: Opportunity:{Id=006L0000008OEtxIAG, Name=Department1: QAI_Test_Account1: Spring: 2015, AccountId=001L000000mWIJXIA4, MNVAlert_Shown__c=false, StageName=Prospecting, RecordTypeId=012L0000000DKZ8IAO} 09:11:14.230 (230279368)|CODE_UNIT_FINISHED|OpportunityAlertExtension <init> 09:11:14.260 (260066812)|CODE_UNIT_STARTED|[EXTERNAL]|01pL0000000R08e|OpportunityAlertExtension get(opp) 09:11:14.260 (260093022)|SYSTEM_MODE_ENTER|true 09:11:14.260 (260115204)|CODE_UNIT_STARTED|[EXTERNAL]|01pL0000000R08e|opp 09:11:14.260 (260142455)|CODE_UNIT_FINISHED|opp 09:11:14.260 (260165264)|CODE_UNIT_FINISHED|OpportunityAlertExtension get(opp) 09:11:14.262 (262142347)|VF_SERIALIZE_VIEWSTATE_BEGIN|066L0000000EUbm 09:11:14.263 (263460613)|VF_SERIALIZE_VIEWSTATE_END 09:11:14.266 (266971105)|CUMULATIVE_LIMIT_USAGE 09:11:14.266 (266971105)|LIMIT_USAGE_FOR_NS|(default)| Number of SOQL queries: 1 out of 100 Number of query rows: 1 out of 50000 Number of SOSL queries: 0 out of 20 Number of DML statements: 0 out of 150 Number of DML rows: 0 out of 10000 Maximum CPU time: 0 out of 10000 Maximum heap size: 0 out of 6000000 Number of callouts: 0 out of 100 Number of Email Invocations: 0 out of 10 Number of future calls: 0 out of 50 Number of queueable jobs added to the queue: 0 out of 50 Number of Mobile Apex push calls: 0 out of 10 09:11:14.266 (266971105)|CUMULATIVE_LIMIT_USAGE_END 09:11:14.267 (267009070)|CODE_UNIT_FINISHED|VF: /apex/Opportunity_Page_Alert 09:11:14.268 (268270387)|EXECUTION_FINISHED
 
Best Answer chosen by SFDCDevQA
SFDCDevQASFDCDevQA
Figured it out.  And of course it was a missing }.  I looked over that syntax a zillion times! 
So this set of lines:
if({!opp.Territory2id==null && opp.MNVAlert_Shown__c==False && (opp.Kind_HSS_STEM__c==null || opp.Kind_HSS_STEM__c == 'Other')}) {
        window.alert("This Opportunity is neither HSS or STEM. Please correct the Discipline and re-save");
        updateStatus(); 

Should have been:
if({!opp.Territory2id==null && opp.MNVAlert_Shown__c==False && (opp.Kind_HSS_STEM__c==null || opp.Kind_HSS_STEM__c == 'Other')}) {
        window.alert("This Opportunity is neither HSS or STEM. Please correct the Discipline and re-save");
        updateStatus(); 
       }

Because it was visualforce Salesforce was not verifying that I had a closing tag and somehow that closing tag got removed in the move from my other environments where it was working.  If I was Charlie Brown I would beat my head against a tree. 

All Answers

Sagar PareekSagar Pareek
On your VF page you have defined the MarkRead function but where are you calling it? I cannot see this in javascript as well and also your javascript calls UpdateStatus method which is not defined anywhere.
 
SFDCDevQASFDCDevQA

I changed the label to Markread from updatestatus just before I posted this and forgot to change it below in the code.   Previously it said updatestatus in all places but still was not calling the method. And the Popup should show even if the method is not called but the Popup isn't showing either. And I verified that my browser isn't blocking them because I opened my dev org and it's working fine there. 
Thanks
Amanda
SFDCDevQASFDCDevQA
Figured it out.  And of course it was a missing }.  I looked over that syntax a zillion times! 
So this set of lines:
if({!opp.Territory2id==null && opp.MNVAlert_Shown__c==False && (opp.Kind_HSS_STEM__c==null || opp.Kind_HSS_STEM__c == 'Other')}) {
        window.alert("This Opportunity is neither HSS or STEM. Please correct the Discipline and re-save");
        updateStatus(); 

Should have been:
if({!opp.Territory2id==null && opp.MNVAlert_Shown__c==False && (opp.Kind_HSS_STEM__c==null || opp.Kind_HSS_STEM__c == 'Other')}) {
        window.alert("This Opportunity is neither HSS or STEM. Please correct the Discipline and re-save");
        updateStatus(); 
       }

Because it was visualforce Salesforce was not verifying that I had a closing tag and somehow that closing tag got removed in the move from my other environments where it was working.  If I was Charlie Brown I would beat my head against a tree. 
This was selected as the best answer