Skip to main content
added 562 characters in body
Source Link
sam_s
  • 976
  • 3
  • 15
  • 32

Update-II Since I'm beginner in SFDC, I'm not 100% confident about this. The data in the field is updated in database but the view state of visualforce page does not have that updated value. When we are trying to inline-edit some fields on the page and save the page, the field values on the page over-rides the values in the data-base. That is the reason why Target Check in this scenario is getting deleted.

Work-around Create a formula field which shows the value of that Target Check and hide the Target Check from the page-layout.

Update-II Since I'm beginner in SFDC, I'm not 100% confident about this. The data in the field is updated in database but the view state of visualforce page does not have that updated value. When we are trying to inline-edit some fields on the page and save the page, the field values on the page over-rides the values in the data-base. That is the reason why Target Check in this scenario is getting deleted.

Work-around Create a formula field which shows the value of that Target Check and hide the Target Check from the page-layout.

added 2160 characters in body
Source Link
sam_s
  • 976
  • 3
  • 15
  • 32

I have a field called Target Check on Case object which was updated by future call from a AfterInsert and AfterUpdate trigger. Since it is a future method, there is a 2-3 second delay and I have refresh the page to view that valueupdated data of that field on a record detail page.

enter image description here

Update

Can't figure it out. Need some reasoning on execution of future methods. From my understanding, we definitely need to refresh the page in-order to render the data from future method trigger. Is it mandatory?

Trigger:
if(Trigger.isAfter)
{
   if(Trigger.isInsert)
   {
     set<Id> caseIds = new set<Id>();
     for(Case cs:Trigger.New)
      {
         if(cs.Priority!=null)
          {
             caseIds.add(cs.Id);
          }
      }
      if(caseIds.size()>0) //also using a static method to prevent recursion 
      {
        UpdateTargetCheckClass.updateField(caseIds);
      }
    }
    if(Trigger.isAfter)
    {
       set<Id> caseIds = new set<Id>();
       for(Case cs:Trigger.old)
       {
          Case newCase = Trigger.newMap.get(cs.Id);
          if(cs.Priority!=newCase.Priority){
           caseIds.add(cs);
          }  
       }
       //call above future method here and static method to prevent recursion
    }
 }
 
 Handler:
 @future
 public static void updateField(set<Id> newCaseIds)
 {
   list<Case> casesToUpdate = new list<Case>();
   // I have to pull the data from related CaseMilestone which made me to use future annotation
   list<Case> updateList = [Select Id, 
                                   Target_Check__c,
                                   (SELECT Id, TargetDate 
                                    FROM CaseMilestones limit 1) 
                                   from Case where Id IN: newCaseIds];
   for(Case cs: updateList)
   {
      CaseMilestone cm = cs.CaseMilestones.size() > 0 ? cs.CaseMilestones[0] : new CaseMilestone();
      if(cm.TargetDate!= null && cs.Target_Check__c != cm.TargetDate)
      { 
        cs.Target_Check__c = cm.TargetDate;
        system.debug('---------Target_Check__c---------'+cs.Target_Check__c);
                casesToUpdate.add(cs);
      }                
   }
   if(!casesToUpdate.isEmpty())
   {
      update updateList;
   }       
  
}

I have a field called Target Check on Case object which was updated by future call from a AfterInsert and AfterUpdate trigger. Since it is a future method, there is a 2-3 second delay and I have refresh the page to view that value on a record detail page.

enter image description here

I have a field called Target Check on Case object which was updated by future call from a AfterInsert and AfterUpdate trigger. Since it is a future method, there is a 2-3 second delay and I have refresh the page to view that updated data of that field on a record detail page.

enter image description here

Update

Can't figure it out. Need some reasoning on execution of future methods. From my understanding, we definitely need to refresh the page in-order to render the data from future method trigger. Is it mandatory?

Trigger:
if(Trigger.isAfter)
{
   if(Trigger.isInsert)
   {
     set<Id> caseIds = new set<Id>();
     for(Case cs:Trigger.New)
      {
         if(cs.Priority!=null)
          {
             caseIds.add(cs.Id);
          }
      }
      if(caseIds.size()>0) //also using a static method to prevent recursion 
      {
        UpdateTargetCheckClass.updateField(caseIds);
      }
    }
    if(Trigger.isAfter)
    {
       set<Id> caseIds = new set<Id>();
       for(Case cs:Trigger.old)
       {
          Case newCase = Trigger.newMap.get(cs.Id);
          if(cs.Priority!=newCase.Priority){
           caseIds.add(cs);
          }  
       }
       //call above future method here and static method to prevent recursion
    }
 }
 
 Handler:
 @future
 public static void updateField(set<Id> newCaseIds)
 {
   list<Case> casesToUpdate = new list<Case>();
   // I have to pull the data from related CaseMilestone which made me to use future annotation
   list<Case> updateList = [Select Id, 
                                   Target_Check__c,
                                   (SELECT Id, TargetDate 
                                    FROM CaseMilestones limit 1) 
                                   from Case where Id IN: newCaseIds];
   for(Case cs: updateList)
   {
      CaseMilestone cm = cs.CaseMilestones.size() > 0 ? cs.CaseMilestones[0] : new CaseMilestone();
      if(cm.TargetDate!= null && cs.Target_Check__c != cm.TargetDate)
      { 
        cs.Target_Check__c = cm.TargetDate;
        system.debug('---------Target_Check__c---------'+cs.Target_Check__c);
                casesToUpdate.add(cs);
      }                
   }
   if(!casesToUpdate.isEmpty())
   {
      update updateList;
   }       
  
}
edited title
Link
sam_s
  • 976
  • 3
  • 15
  • 32

Data in a Custom field value getting deleted itself

added 174 characters in body
Source Link
sam_s
  • 976
  • 3
  • 15
  • 32
Loading
Source Link
sam_s
  • 976
  • 3
  • 15
  • 32
Loading