+ Start a Discussion
Vadivel MuruganVadivel Murugan 


My old value does not come, only display new map value why. how can i get old map value in apex trigger
Can you share your code here? so ithat it will be easy for us to assist you
Note that old map is only available in update and delete triggers.
Suppose your field name is My_Date__c and SObject is Account then you need to do this - 

for(Account a: trigger.new) {
 if(a.My_Date__c != trigger.oldMap.get(a.Id).My_Date__c) {
  //do something here

Since trigger.old and trigger.oldMap are null for Insert and Undelete triggers, this should only work for Updates and Deletes.

If this resolves your problem, please mark the question as Resolved.
Vadivel MuruganVadivel Murugan
public void OnAfterUpdate(Map<id,Visits__c> VisitsNewMap,Map<id,Visits__c> VisitsOldMap){

private void CheckRevisiedVisitDate(Map<id,Visits__c> VisitsNewMap,Map<id,Visits__c> VisitsOldMap)
        Visits__c previsit=new Visits__c();
        Visits__c changevisit=new Visits__c();
        Visits__c visilist=new Visits__c();
        Visits__c managerapproval;     
       for(Visits__c result: VisitsOldMap.values())
        for(Visits__c result: VisitsNewMap.values())
        managerapproval = [select id,name,Revised_Actual_Visit__c from Visits__c where id =:visilist.id];
            if(previsit.Actual_Service_Date__c.month()==previsit.Actual_Service_Date__c.month() && managerapproval.Revised_Actual_Visit__c!=true){
                  for(Visits__c visit: VisitsNewMap.values()){
                    visit.addError('Manager can only reschedule the actual visit in different month');

    *Method Name     : CheckManagerApproval
    *Description     : Check Manager Approval for Actual Visit Date
    *Arguments       : new Visit list
    private void CheckManagerApproval(Map<id,Visits__c> VisitsNewMap)
    Visits__c check;
         for(Visits__c result: VisitsNewMap.values()){
         check = [select id,name,Revised_Actual_Visit__c from Visits__c where id =:result.id];
         update check;

Upadte me....
trigger,Old is  not available for insert make sure your code is running on update . before all that make sure you trigger is defined to run on update 

trigger HelloWorldTrigger on Book__c (before update) {

Vadivel MuruganVadivel Murugan
I can call my trigger function in only afetr update field
Which ever method where you want to do this check, should receive trigger.oldMap and trigger.new/newMap as arguments.
In your case that should become - 

Suppose its the method - CheckRevisiedVisitDate(VisitsNewMap,VisitsOldMap) and field Visit_Date_c

then you need to do - 

for(Visit__c v : VisitsNewMap.Values()) {
 if(v.Visit_Date__c != VisitsOldMap.get(v.Id).Visit_Date__c) {
  //your code here