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
QQQQQQQQQQ 

can we check if a field is changed before save to display in vf page

Waqar Hussain SFWaqar Hussain SF
Can you please be more specific about what you are looking for?

Do you want to check whether a field is changed on a VF page before saving it?
IF yes, then you can query the record using ID and can get old value from server and then can compare the value which is going to updating in the field and the value stored in the server. 
QQQQQQQQQQ
Hi Waqar,
Thanks for ur reply .I will explain u my scenario can u please help me out in that as I m new to salesforce. I need to update the Agent name in custom object and when I click on Save i need to save the record and one pop up box should display spontanauesouly.And that  pop box should dispaly only when Save is done for Name change and for other default save should work and no popup 

 
Waqar Hussain SFWaqar Hussain SF
OK got it. So you have Save button on your VF page and when the agent name is changed, you want to show a popup.

So on your save button's method, match the value which is being updated in the agent name field with the value stored in database. For example below is your save method.
public boolean ShowAlert {get; set;}

public void SaveRecord(){

	Custom_Object__c oldRec = [Select Id, Agent_Name__c from Custom_Object__c where ID : SOME_VAR];
	Custom_Object__c obj = new Custom_Object__c();
	obj.Id = 'Some ID';
	obj.Agent_name__c = 'Some values';
	update obj;

	ShowAlert = false;
	If(oldRec.Agent_Name__c != obj.Agent_Name__c)
	showAlert = true;

}


based on the ShowAlert propoerty you can show a popup by calling your javascipt method. 
QQQQQQQQQQ
thank you waqar
QQQQQQQQQQ
You have any idea how to give default save as this popup should come only on Agent name change. when other feild are changed default save should be done 
 
Waqar Hussain SFWaqar Hussain SF
This can not be done via Standard Save method. You will have to write your own custom save method.
QQQQQQQQQQ
Getting this error 
Unknown property 'OnBehalf_Service_Requests__cStandardController.IntroCallOppCreation'

Vf 
<apex:page standardController="OnBehalf_Service_Requests__c" extensions="IntroCallOppCreation" >
    <style>
        .custPopup{
        background-color: white;
        border-width: 2px;
        border-style: solid;
        z-index: 9999;
        padding:10px;
        position: fixed;
        left: 50%;
        /* These are the 3 css properties we need to change so the popup 
        displays in the center of the screen. First set the width. Then set 
        margin-left to negative half of what the width is. We can add 
        the height property for a fixed size pop up.*/
       /* width: 500px;
        margin-left: -220px;
        top:125px;
        }
        .popupBackground {
        background-color:black;
        opacity: 0.20;
        filter: alpha(opacity = 20);
        position: absolute;
        width: 100%;
        height: 100%;
        top: 0;
        left: 0;
        z-index: 9998;
        }        
    </style>   
    <apex:form >
        <!-- ****************************** Dialog Box*********************************** -->
    <div align="center">
      <apex:commandbutton value="save" id="Validate"  action="{!doSave}"/> &nbsp;&nbsp;&nbsp;&nbsp;
            </div >
        <apex:outputPanel styleClass="popupBackground" rendered="{!checkBoxFlag}" layout="block" id="popupBackground"/>            
        <apex:outputpanel rendered="{!checkBoxFlag}" styleClass="custPopup"  layout="block" id="custPopup">
            <apex:pageBlock >
                <p style="font-size:14.5px;text-align:center;"><b>Create New IntroCall for New PAM </b><br/><br/></p>
        
       <apex:actionFunction name="OnclickYes" action="{!IntroCallOppCreation.OnclickYes}"/>

<input type="radio" onclick="OnclickYes();"  name="OnclickYes" value="Yes"> {!$Label.Yes}
    </input>
  <apex:actionFunction name="OnclickNo" action="{!IntroCallOppCreation.OnclickNo}"/>
<input type="radio" onclick="OnclickNo();"  name="OnclickNo" value="No"> {!$Label.No} 
    </input>

            </apex:pageBlock>
        </apex:outputPanel>
    </apex:form>
</apex:page>




  apex class 
Public class IntroCallOppCreation{
 public string id;
public boolean checkBoxFlag {get;set;}
OnBehalf_Service_Requests__c obsr;
OnBehalf_Service_Requests__c obsrCurrRec;
public IntroCallOppCreation(ApexPages.StandardController Controller){
this.obsrCurrRec = (OnBehalf_Service_Requests__c)Controller.getRecord(); //old and new name will be fetched 
        Id = ApexPages.currentPage().getparameters().get('Id');
    OnBehalf_Service_Requests__c obsr=[select Id,PAM_Agent__c from OnBehalf_Service_Requests__c where Id=:Id];
        checkBoxFlag = false;
    }
        //Method for creating the intro call 
 
    Public pageReference showpopup(){
      checkBoxFlag = true;
          PageReference pr = new PageReference('/apex/IntroCallOppCreation'); 
            return pr;
    }
            public pageReference OnclickYes(){
            try{
             
          //  CRU_OneTimeGoaljob obj = new CRU_OneTimeGoaljob();  
           // Database.executeBatch(obj); 
            PageReference pr = new PageReference('/'+id); 
            return pr;
            }
             catch (Exception ex){
           system.debug('***Error*** '+ex.getStackTraceString());
            return null;
            }
            }
      public pageReference OnclickNo(){
          PageReference pr = new PageReference('/'+id); 
            return pr;
      }
            
      Public PageReference doSave(){
      if(obsrCurrRec.PAM_Agent__c!= obsr.PAM_Agent__c) {
      update obsrCurrRec;
            showPopUp();    
      }
      PageReference pr = new PageReference('/'+id);
             return pr;

}
}
Waqar Hussain SFWaqar Hussain SF
<apex:page standardController="OnBehalf_Service_Requests__c" extensions="IntroCallOppCreation" >
    <style>
        .custPopup{
        background-color: white;
        border-width: 2px;
        border-style: solid;
        z-index: 9999;
        padding:10px;
        position: fixed;
        left: 50%;
        /* These are the 3 css properties we need to change so the popup 
        displays in the center of the screen. First set the width. Then set 
        margin-left to negative half of what the width is. We can add 
        the height property for a fixed size pop up.*/
       /* width: 500px;
        margin-left: -220px;
        top:125px;
        }
        .popupBackground {
        background-color:black;
        opacity: 0.20;
        filter: alpha(opacity = 20);
        position: absolute;
        width: 100%;
        height: 100%;
        top: 0;
        left: 0;
        z-index: 9998;
        }        
    </style>   
    <apex:form >
        <!-- ****************************** Dialog Box*********************************** -->
    <div align="center">
      <apex:commandbutton value="save" id="Validate"  action="{!doSave}"/> &nbsp;&nbsp;&nbsp;&nbsp;
            </div >
        <apex:outputPanel styleClass="popupBackground" rendered="{!checkBoxFlag}" layout="block" id="popupBackground"/>            
        <apex:outputpanel rendered="{!checkBoxFlag}" styleClass="custPopup"  layout="block" id="custPopup">
            <apex:pageBlock >
                <p style="font-size:14.5px;text-align:center;"><b>Create New IntroCall for New PAM </b><br/><br/></p>
        
       <apex:actionFunction name="OnclickYes" action="{!OnclickYes}"/>

<input type="radio" onclick="OnclickYes();"  name="OnclickYes" value="Yes"> {!$Label.Yes}
    </input>
  <apex:actionFunction name="OnclickNo" action="{!OnclickNo}"/>
<input type="radio" onclick="OnclickNo();"  name="OnclickNo" value="No"> {!$Label.No} 
    </input>

            </apex:pageBlock>
        </apex:outputPanel>
    </apex:form>
</apex:page>

use above code
QQQQQQQQQQ
Hi Waqar,

 Thank you so much i didnt got any error but while clikcing on save I am  not getting any popup.Is there s any misytake in the code .