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
Ratheven SivarajahRatheven Sivarajah 

I am trying to calculate the total amount of time when a milestone is paused

I have a field called (stopped since) that shows the time when the milestone is paused but when it gets activated again it disappears. If I pause it again it shows the current time. How do I calculate the total amount of time when the milestone is in pause. 
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Ratheven,

You can create a new field to store the time when the milestone is changes from pause to activated  so you can add them and show it.

Thanks.
 
Ratheven SivarajahRatheven Sivarajah
Hey Sai. How can a field hold more then 1 time stamp?
 
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Ratheven,

You cannot hold more than 1 Value but you have to sum the value with previous value and save it.

For example:  stopped since field contains: 8:30

you have activated the milestone then new field will save values as current time- stoppedsince.

Next time when it is again stopped the field contains: 9:40

when you again activate this will add old value + currenttime-stoppedsince field value.

Let me know if you face any issues.

If this solution helps, Please mark it as best answer.

Thanks,
Ratheven SivarajahRatheven Sivarajah
I understand now. The stopped since field contains a date like this 2023-02-10, 9:54 a.m. I am fairly new to salesforce, How do I perform your formula when the stopped since field dissapears when it gets activated. If you have a step to step guide would really appreciated!
Shri RajShri Raj
trigger MilestoneTrigger on Milestone (before insert, before update) {
  for (Milestone m : Trigger.new) {
    if (m.Status__c == 'Paused') {
      if (!m.IsFirstPause__c) {
        m.IsFirstPause__c = true;
        m.PauseStartTime__c = m.Stopped_Since__c;
      }
    } else if (m.IsFirstPause__c) {
      m.IsFirstPause__c = false;
      m.TotalPauseTime__c += (m.Stopped_Since__c - m.PauseStartTime__c).totalSeconds() / 3600;
    }
  }
}