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
sfdc@isha.ax1814sfdc@isha.ax1814 

Urgent Requirement:Help to write the trigger

Hi, I have one feedback__c object and  having status picklist field 
status values are  open,draft,pending reply and pending submiter

we have extra fileds created to capture the time difference opentat__c,replytat__c etc

my requirement is i want to do calculate time difference  and display in hours when the status is changed to open to draft --- stored in the opentat__c filed

pendingreply to pending submitter---replytat__c
pending submiter to open ---opentat__c


please anybody  help me out to resolve this .



Regards,
Isha

 

Shabbir ShaikShabbir Shaik
Hi sfdc@isha,

Instead of Trigger you can use workflow,

set condition when it changes from open to draft for field update and calculate difference between the CreatedDate and LastModified Date
Vidhyasagaran MuralidharanVidhyasagaran Muralidharan
Like can you brief more.Like from understanding you insert a record in feedback object with status field as open and while inserting  in opentat__c will contain the current date and time then with the update trigger you are changing the status to draft and by that time opentat__c field should calculate the open status time and draft status change time.similarly for the replystat__c .whether my understanding is correct.then,case like draft to pendingreply will it need to be captured??.
Bhawani SharmaBhawani Sharma
Use two separate fields, one to hold the Start Time and 2nd to hols end time. Then use workflow rule to get these populated. Then use a formual field to find out the age End Date - Start Date.
sfdc@isha.ax1814sfdc@isha.ax1814
Hi  Thanks  All for your reply.

HI shabbir
actually here we ahve to crete 7 formules so difficult write 7 seperate workflows.so we are planing to write trigger and put everything in the single trigger.


Hi Vidhya,

your understanding is bit correct actually when we are updating on Feedback object with status field  changes then need to capture the time between two status value for ex:As i mentioned from status value is open to draft then the difference time will be captured and put into the opentat__c field  for firsttime only means if opentat__c filed is not empty then it will not fire like that we have to capture replytat__c and opentat__C.


Regards,
Isha.
Vidhyasagaran MuralidharanVidhyasagaran Muralidharan
Trigger feedbackupdate on feedback__C(before update)
{
feedback__c f = new feedback__c();
for(feedback__c f1 :trigger.new)
{
\\if the record status changes from open to draft
if(f1.status__c=='draft')
{
f.opentat__C=ROUND(8*(
(5*FLOOR((DATEVALUE(Createddate)-DATE(1900,1,8))/7)+
MIN(5,
MOD(DATEVALUE(CreatedDate) - DATE(1900,1,8),7)+
MIN(1,24/8*(MOD(date/time_1 - DATETIMEVALUE('1900-01-08 16:00:00'),1))
)
)
)
-
(5*FLOOR((DATEVALUE(lastmodifieddate)-DATE(1900,1,8))/7)+
MIN(5,
MOD(DATEVALUE(date/time_2)-DATE(1996,1,1),7)+
MIN(1,24/8*(MOD(date/time_2-DATETIMEVALUE('1900-01-08 16:00:00'),1))
)
)
)
),
0)
}
\\if record status changes from pendingreply to pending submitter
if(f1.status__c=='pending submitter')
{
f.replytat__c=ROUND(8*(
(5*FLOOR((DATEVALUE(lastmodifieddate)-DATE(1900,1,8))/7)+
MIN(5,
MOD(DATEVALUE(lastmodifieddate) - DATE(1900,1,8),7)+
MIN(1,24/8*(MOD(date/time_1 - DATETIMEVALUE('1900-01-08 16:00:00'),1))
)
)
)
-
(5*FLOOR((DATEVALUE(now())-DATE(1900,1,8))/7)+
MIN(5,
MOD(DATEVALUE(now())-DATE(1996,1,1),7)+
MIN(1,24/8*(MOD(date/time_2-DATETIMEVALUE('1900-01-08 16:00:00'),1))
)
)
)
),
0)
}
\\if the record status changes from pending submitter to open
if(f1.status__c=='open')
{
f.opentat__c=ROUND(8*(
(5*FLOOR((DATEVALUE(lastmodifieddate)-DATE(1900,1,8))/7)+
MIN(5,
MOD(DATEVALUE(lastmodifieddate) - DATE(1900,1,8),7)+
MIN(1,24/8*(MOD(date/time_1 - DATETIMEVALUE('1900-01-08 16:00:00'),1))
)
)
)
-
(5*FLOOR((DATEVALUE(now())-DATE(1900,1,8))/7)+
MIN(5,
MOD(DATEVALUE(now())-DATE(1996,1,1),7)+
MIN(1,24/8*(MOD(date/time_2-DATETIMEVALUE('1900-01-08 16:00:00'),1))
)
)
)
),
0)
}
}
}
you can try like this.but not sure about your requirement