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
Arvind1Arvind1 

calling apex method after clicking OK on alert box

Hi All,

 

I have a requirement where I have to display an alert message first time when the case owner opens the case detail page.

 

The alert should not be displayed when the case owner opens the case detail page for the second time.

For this when the user clicks on Ok on alert box first time, I want to call a controller method to insert a record in an object and then by using the record count of this object, I am displaying the alert only when the count is 0.

 

But I am not able to call the controller method after the alert.

 

Following is the code I am using.

<apex:page showHeader="false" standardController="Case" extensions="Sendemailinsert" action="{!countemail}">
  <script language="javascript">
     function test(){
        
       if({!usercheck}==true)
       alert('Golden Rules for this account were updated after the last updates were made for this case. Please review golden rules before working on this case.');
     }
  </script>
  <body onLoad="javascript&colon; test();">
    
  <p></p>
 
  </body>
  
</apex:page>

 

public class Sendemailinsert {

Case objcas=new Case();
Case cs=new Case();
    public Sendemailinsert(ApexPages.StandardController controller) {
    cs=(Case)controller.getrecord();
    objcas=[select ownerid from Case where id=:cs.id];
    system.debug('owner'+objcas.ownerid);
    }
    public Case getcs(){
        return objcas;
    }
    public Boolean getusercheck(){
        system.debug('userid'+userinfo.getuserid());
        system.debug('ownerid'+objcas.ownerid);
        if(objcas.ownerid==userinfo.getuserid() && emailcount==0)
            return true;
        else 
            return false;
    }
    public Integer emailcount{get;set;}
    public void countemail(){
      emailcount=[select count() from Send_Email__c where Case__c=:cs.id and Sent__c=true and Notification_Type__c='GR Popup'];  
    }
    public pagereference sendemailsave(){
    Send_Email__c obj_sendemail=new Send_Email__c();
    obj_sendemail.Case__c=cs.id;
    obj_sendemail.Sent__c=true;
    obj_sendemail.Notification_Type__c='GR Popup';
    obj_sendemail.Notification__c='Golden Rules for this account were updated after the last updates were made for this case. Please review golden rules before working on this case.';
    insert obj_sendemail;
    pagereference pg=new pagereference('/'+cs.id);
    pg.setredirect(true);
    return pg;
    }
}

 

Here I am not able to understand where should I call the sendemailsave method. I tried to give this inside the function test(). But it throwed an error "Unknown property 'CaseStandardController.sendemailsave'".

 

Any suggestion will be helpful.

 

Thanks

Arvind

 

suresh.csksuresh.csk

Hi.

You have to use <apex:actionFuntion > in your VF page to call Apex method.

 

check the below link

 

http://blog.sforce.com/sforce/2009/10/passing-java script-values-to-apex-controller.html#more

 

or search <apex:actionFunction > in VF tutorials

 

 

cheers

suresh