I am a beginner in Salesforce. I am trying to implement a code wherein user will get a alert message (some sort of notification ) when a field value is null. Although it will allow the user to save that record. I wrote a VF page. that I will embed with the standard page layout. Let me know if that is the correct approach.

<apex:page standardController="Opportunity" action="{!markread}" extensions="OppExtension">
      if(!Opportunity.Country__c != null {
          alert("Please fill in the country details");

and my extension controller:

public with sharing class OppExtension {
     ApexPages.StandardController controller;
     public OppExtension(ApexPages.StandardController controller) {
         this.controller = controller;
     public void markread() {
         Opportunity o = (Opportunity) controller.getRecord();
         o.MessageShown__c = true;
         update o;

Visualforce page

<!-- Using java script in visualforce page -->
<apex:page extensions="OppExtension">
  <apex:form >
        <apex:pageBlock >
           Input Here  : <apex:inputText id="inptID"/>
                       <apex:commandButton onclick="MyjavaFunction('{!$Component.inptID}')" value=" Submit "/>

  <!-- Java script starts Here -->
   function MyjavaFunction(ReceiveInputID){

    var inputValue = document.getElementById(ReceiveInputID).value;
         if(inputValue == ''){
            alert('You did not eneter any value in input box');
            alert(' You entered :: '+inputValue); 


Here is one code which may be useful for u


  • Hi, problem here is ..the layout where I am planning to add this logic is a standard object's page layout. so I am not sure how to use "document.getElementById(ReceiveInputID).value" in this page since I do not know "ReceiveInputID"'s avlue here. – Apurbo Aug 7 '14 at 9:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.