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
Aaditya SinghAaditya Singh 

How to create a trigger to calculate the number of days a field was in stop status

Create a new object Survey Request with below fields,
  1. Status – Pick list(Options: Open, Close , Start, Stop)
  2. Stop Started date – date
  3. Total Stop Duration in days-- Integer
  • Create a trigger on survey request to capture the total days for which the survey request was stopped and store the same in Total Stop Duration in day’s field.
Khan AnasKhan Anas (Salesforce Developers) 
Hi Aaditya,

Greetings to you!

You don't need a trigger for that, you can do it through workflow rules.

To calculate the duration of how long a field stays in a particular Picklist Value, please refer to the below knowledge article.

https://help.salesforce.com/articleView?id=000213870&type=1

Also, please refer to below links which might help you further.

https://developer.salesforce.com/forums/?id=906F00000008pC4IAI

https://salesforce.stackexchange.com/questions/106356/how-to-calculate-the-age-of-the-stage-field-when-it-changes-from-one-stage-to-an

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
Aaditya SinghAaditya Singh
Hi Anas,

I really appriciate your help regarding above issue but i have got an assignment in which i need to create a trigger for the same.
I have already gone through this article and this is very helpful but currently I am looking for Trigger solution.
Raju yadavRaju yadav
Hi Aaditya,
You can enable field History traking on status field.
It might help you.
SHRAVAN K 6SHRAVAN K 6
Aditya, you may need a schedule job to run everyday at certain time to update records.