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
sumanth v 18sumanth v 18 

Alert Box on Pick list value change on Case Object

I tried with this peace of code, whenever i change value alert appears but even reloading the page alert appears which shouldn't. How to skip alert on reloading the page.

<apex:page standardController="Case" rendered="{!Case.Stage__c = 'Pending'}">
<script type="text/javascript">
window.alert("Static Content");
</script>
</apex:page>


Also i tried in putting stage condition in action attribute but it is throwing Content cannot be displayed: SObject row was retrieved via SOQL without querying the requested field: Case.Stage__c [No Apex class associated to this page]
<apex:page standardController="Case" Action="{!Case.Stage__c = 'Pending'}">
<script type="text/javascript">
window.alert("Static Content");
</script>
</apex:page>



 
shrish mysoreshrish mysore
In the rendered attribute you should do logical function like IF(Case.Stage__c == 'Pending'), and Action atribute is used to call a action method before the page is loaded, not used for initialiation or condition checking.
Aman MalikAman Malik
Hi,
Is the above snippet is a complete one. if no, please post comlete snippet.
If you only want a alert for stage pending, then update snippet with below:
<apex:page standardController="Case" >
<script type="text/javascript">
var a = '{!Case.Stage__c}';
if(a == 'Pending'){
    window.alert("Static Content");
}
</script>
</apex:page>
Hope this will help.

Please like the answer and mark it as best if this helps.

Thanks,
Aman

 
sumanth v 18sumanth v 18
Hi Aman,
If you only want a alert for stage pending, then update snippet with below: YES
I tried your code it throws alert, also when i reload the page it throws alert which shouldn't. 
 
sumanth v 18sumanth v 18
Hi Shrish,

I tried as per your comments too. I am able to get alert in above scenarios, issue is while refreshing the page also the alert fires which i need to stop.

<apex:page standardController="Case" rendered="{!If(Case.Stage__c = 'ADOPS: Miscellaneous request for Trafficking' ,true,false)}">

<script type="text/javascript">

window.alert("Static Content");
</script>
</apex:Page>
Aman MalikAman Malik
Hi,

Can you post your code snippet

Thanks
sumanth v 18sumanth v 18
Please find below. My requirement is to display alert when the case stage = 'ADOPS: Miscellaneous request for Trafficking'. Alert appears with below code and saves the record. After that i tried in refreshing the page again alert fired which i need to stop.
<apex:page standardController="Case">
<script type="text/javascript">
var a = '{!Case.Stage__c}';
if(a == 'ADOPS: Miscellaneous request for Trafficking'){
window.alert("Static Content");
}
</script>
</apex:page>
Aman MalikAman Malik
Your code loads script every time when page loads. therefore its firing alert every time.
How you actually updating case stage value?
sumanth v 18sumanth v 18
I am updating in Case detail Page manually. Yes as you said code loads script eveytime when page loads(only for records which has case stage = 'ADOPS: Miscellaneous request for Trafficking'). Can u help me how to stop this?
Aman MalikAman Malik
just let me know:
When you want this alert to be popup?
As you are updating page from case detail layout. How would you want it to be fire?
would you like it to be fire automatically?

Thanks
sumanth v 18sumanth v 18
would you like it to be fire automatically? YES

I am updating in standard Case detail page, when the stage field got udpated with the mentioned value, alert should fire automatically
Aman MalikAman Malik
As case detail page and your custom vf page run in different context. So, its not possible to trigger alert on your custom page when case update on some other page.
Alternative:
You could update stage from your custom vf page by using standard controller.

Thanks,
Aman
 
sumanth v 18sumanth v 18
So you mean to say standard detail page will get overridden in this scenario. Am i right?
 
Aman MalikAman Malik
Standard detail page will not get overriden. Your custom vf will get capable of updating case record.
Thanks
sumanth v 18sumanth v 18
Your custom vf will get capable of updating case record. Could you please share if you have a related code?
Aman MalikAman Malik
Give a try to below snippet:
<apex:page standardController="Case">
  <apex:form>
  <script>
      function fxn(){
          var a = document.getElementsByClassName('stage1')[0].value;
          if (a=='ADOPS: Miscellaneous request for Trafficking'){
              window.alert("Static Content");
          }
      }
  </script>
    <apex:pageBlock title="My Content" mode="edit">
      <apex:pageBlockButtons>
        <apex:commandButton action="{!quicksave}" value="Save" onclick="fxn()"/>
      </apex:pageBlockButtons>
      <apex:pageBlockSection title="My Custom detail page" columns="2">
        <apex:inputField styleClass="stage1" value="{!Case.Stage__c}"/>
      </apex:pageBlockSection>
    </apex:pageBlock>
  </apex:form>
</apex:page>
Thanks
 
Aman MalikAman Malik
Hi sumanth,
Is above-mentioned solution working for you? Kindly let me know.

Thanks
sumanth v 18sumanth v 18
Hi Aman,

Nope, we shouldn't create a custom button in our requirement. In above scenario we need to overide existing standard button.

Thanks
Sumanth