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
Aidel BruckAidel Bruck 

How to create a popup message that will show only if certain criteria are met.

When a certain costum object is created and saved I would like a popup message to show only if certain critiria are relevant. 
please advice me how to do this
Best Answer chosen by Aidel Bruck
Veenesh VikramVeenesh Vikram
Try replacing 
var status={!servrec.Status__c}
with
var status="{!servrec.Status__c}"

Similarly do:
 var servicename = "{!servrec.name}";

All Answers

Aidel BruckAidel Bruck
Thanks Veenesh, 
Would you be able to point me towards some code that can do this. I am stil learning the ropes in VF and could use some sample code.
All the best, 
Aidel
Aidel BruckAidel Bruck
I'm sorry, 
I am still so confused. 
I just need to have a popup that will show if certain critiria are relevant. 
I need some sample code for the VF page and the extention. Anybody?
Veenesh VikramVeenesh Vikram
Hi,

Try the below code, this VF page can be embedded "Inline" into the Account's detail page. It will show an alert if the "Account Number" for an account is null.
 
<apex:page standardController="contact" extensions="inlinecontroller">
	<script>
		window.onload = function() {
		  var num = {!accRec.accountnumber};
		  if(num == null){
			alert("Please enter Account Number");
		  }
		};
	</script>
</apex:page>

public with sharing class inlinecontroller {
Public id accId;
Public account accRec{get;set;}
    public inlinecontroller(ApexPages.StandardController controller) {      
     accId = ApexPages.currentPage().getParameters().get('id');
      if(accRecId != null)
         accRec = [select id,name,accountnumber,annualrevenue from account where id =:accRecId];
    }
	
}

Hope this helps.

Best Regards
Veenesh
Aidel BruckAidel Bruck
ok, after some work I came up with the following code. I am running the test and getting and error that I am derefrencing a null object. I am not sure what is wrong with this code.

VF page
***************
<apex:page standardController="Comment__c" extensions="CommentUpdateStageController">
    <script>
        window.onload = function() 
        {
          var status= {!servrec.Status__c};
          var servicename{!servrec.name};
          
          if(status == 'closed' &&servicename.contains('Medical_Directory_Program'))
          {
              alert('You are adding a comment to a service that is closed. Please change the stage and status accordingly');
          }
        };
    </script>
</apex:page>

extention
************
<apex:page standardController="Comment__c" extensions="CommentUpdateStageController">
    <script>
        window.onload = function() 
        {
          var status= {!servrec.Status__c};
          var servicename{!servrec.name};
          
          if(status == 'closed' &&servicename.contains('Medical_Directory_Program'))
          {
              alert('You are adding a comment to a service that is closed. Please change the stage and status accordingly');
          }
        };
    </script>
</apex:page>

test
*********
@istest
private class TestCommentUpdateStage 
{

    public Account a= new account();
    public opportunity o= new opportunity();
    public opportunity o2= new opportunity();
    public comment__C c= new Comment__C();
    public comment__C c2= new Comment__C();
    
    static testMethod void myUnitTest()
    {
         Account a= new account();
         opportunity o= new opportunity();
            opportunity o2= new opportunity();
        comment__C c= new Comment__C();
        comment__C c2= new Comment__C();
        a= TestDataFactory.createPersonAccount('Cohen');
        insert a;
        o= testDataFActory.createmedicaldiropportunity(a);
        insert o;
        o2= testdatafactory.createMedicalBillAssistopportunity(a);
        insert o2;
        c= testdatafactory.createcomment(o);
        c2= testdatafactory.createComment(o2);
        insert c;
        insert c2;
        Test.Starttest();
      
            ApexPages.StandardController stdController = new ApexPages.StandardController(c);
         CommentUpdateStageController ext = new CommentUpdateStageController(stdController);
         
        Test.Stoptest();
    }
}
Aidel BruckAidel Bruck
Here it is the problematic line is in in bold

public with sharing class CommentUpdateStageController
{
Public id commentId;
public id serviceID;
    
    Public opportunity servRec{get;set;}
    Public Comment__C CommentRec{get;set;}
    
    public CommentUpdateStageController(ApexPages.StandardController controller) 
    {     
     commentid = ApexPages.currentPage().getParameters().get('id');
      if(commentid != null)
         commentRec= [select id, Service__c from comment__C where id =:commentId];
     if(CommentRec.Service__c!= null)   
         servRec = [select id,Status__c, stageName, RecordTypeId, name from opportunity where id =:commentRec.Service__c];
    
    }
}
Aidel BruckAidel Bruck
thank so much for your help thus far. 
Your solution really worked. The test code runs succesfully. 
When I try to get the page to show in salesforce itself nothing happens.
Any idea why this is?
Aidel BruckAidel Bruck
I believe I am doing that in the below bolded line:

public with sharing class CommentUpdateStageController
{
Public id commentId;
public id serviceID;
    
    Public opportunity servRec{get;set;}
    Public Comment__C CommentRec{get;set;}
    
    public CommentUpdateStageController(ApexPages.StandardController controller) 
    {     
     commentid = ApexPages.currentPage().getParameters().get('id');
      if(commentid != null)
         commentRec= [select id, Service__c from comment__C where id =:commentId];
     if(CommentRec.Service__c!= null)   
         servRec = [select id,Status__c, stageName, RecordTypeId, name from opportunity where id =:commentRec.Service__c];
    
    }
}
Aidel BruckAidel Bruck
opening the vf page inline.
not seeing any error
Aidel BruckAidel Bruck
yes, I am opening the vf page inline in a comment detail page only. 

I exchanged the code with you code above, And still, Nothing at all doing.
Aidel BruckAidel Bruck
I pressed F12 and saw an error
" Uncaught ReferenceError: Closed is not defined "
on the line - var status={!servrec.Status__c}
 
Veenesh VikramVeenesh Vikram
Try replacing 
var status={!servrec.Status__c}
with
var status="{!servrec.Status__c}"

Similarly do:
 var servicename = "{!servrec.name}";
This was selected as the best answer
Aidel BruckAidel Bruck
Thank you so much for all your help! 
I got it to work.