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
B TulasiB Tulasi 

count time from different records.

Hi All,

I have one custome field i.e. Time__C. I need to count time from different records within the object. what we counted time will be store in another custom field i.e Toatal_Time__C.
For Example :
Record1 : Time__C=2 hours.
Record2 : Time__C=3 hours.
Record3 : Time__C=2 hours.

So, Total_Time=7 Hours.

Thanks in advance
Thulasi.
B TulasiB Tulasi
Using VF Page through controller
Chandra Sekhar CH N VChandra Sekhar CH N V
Use a for loop, iterate the list and them perform the addition. take below sample code:
list<"Your object"> x= [select time__c from Your object ];

for(Your object y:x ){
    total_time =total_time+y.time__c;
}

 
shiva pendemshiva pendem
HI Tulasi,
We can achieve this using trigger, have a look on below trigger.

Trigger Mytrigger on Object(before insert,before update)
{
    List<Object> objList = [seelct id,time__c from object] ;
    Decimal totaltime =0;
    for(object objtime : objList){
         totaltime += objtime.time__c;
     }
    for( Object obj:Trigger .new ){
         obj.total_time__c = totaltime;
     }

 }


Hooe this will be helpful

Thanks,
Shiva