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"/>
</apex:form>
<script>
if ({!Opportunity.Amount}>10000 && {!!Opportunity.messageshown__c}) {
alert ("Contact Mr. X");
markread ();
}
</script>
</apex:page>
Controller:
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;
}
}
messageshown
custom field is false then display the message and set the fieldmessageshown
custom field to true .messageShown
and make sure that default value for this field is false. With this every time a opportunity is created, the fieldmessageShown__c
will be false by default. In the inline vf page, check ifmessageShown__c
is false and satisfies your crtieria(opp amount > 10000) then display alert and set the fieldmessageShown__c
to true. If the same opp is opened again 'messageShown__c' field will be true and don't show the pop up.