I have a requirement to display a popup message ONLY when the opp is created and it satisfies a condition (for instance, amount >100000). Im stuck here at the implementation of the javascript and how to invoke from apex:

Finally, got this to work:

VF page:

<apex:page standardController="opportunity"  extensions="oppMessage" >

<apex:form >
   <apex:actionFunction action="{!markread}" name="markread"/>


 if ({!Opportunity.Amount}>10000 && {!!Opportunity.messageshown__c})   { 

             alert ("Contact Mr. X");

             markread ();





public  class oppMessage {

 ApexPages.StandardController controller;

 public oppMessage(ApexPages.StandardController controller) {
        this.controller = controller;
    public void markread() {
        Opportunity o = (Opportunity)controller.getRecord();
        o.MessageShown__c = true;
        update o;
  • 1
    Problem is that trigger is database level, and Visualforce is View level of Force.com platform. In this case, just a visualforce page with pop-up on load will be enough. About popup -- nice example can be found here -- salesforce.stackexchange.com/questions/490/…, just adjust your criteria. TO ensure that message is shown only once, create one more field, called Message shown, and set that to true after first view. That may require some APEX logic
    – kurunve
    May 22, 2017 at 14:19
  • 1
    Is there a way to pass information about the new record (like trigger.new) rather than creating a new field?
    – Sammy
    May 22, 2017 at 14:27
  • no, there are no way. Problem is that there are multiple ways, how to create an record in salesforce, so, and UI is only one of that. If you want to redirect into a custom VF page only for manually created records, please create custom New VF page for opportunity, override Save button, that saves record and redirect to your page with some URL parameter, like show popup. That is another solution how to achieve desired functionality
    – kurunve
    May 22, 2017 at 14:31
  • 1
    I am not sure if you really need to override the Opportunity view with VF page but you can do this way: 1) create a inline vf page for opp 2) drop it on the layout and set height and width to zero 3) Inside the vf page extension, you can check if the messageshown custom field is false then display the message and set the field messageshown custom field to true .
    – javanoob
    May 22, 2017 at 14:38
  • 2
    Create a new custom field on the opportunity object of type checkbox and give name as messageShown and make sure that default value for this field is false. With this every time a opportunity is created, the field messageShown__c will be false by default. In the inline vf page, check if messageShown__c is false and satisfies your crtieria(opp amount > 10000) then display alert and set the field messageShown__c to true. If the same opp is opened again 'messageShown__c' field will be true and don't show the pop up.
    – javanoob
    May 22, 2017 at 14:46


You must log in to answer this question.

Browse other questions tagged .