You need to sign in to do that
Don't have an account?
count time from different records within the custom Object.
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.
Trigger :
trigger TimeCount on Work_Log_Sheet__c (before insert, before update) {
decimal count;
Set<Id> sid = new Set<Id>();
List<Work_Log_Sheet__c> lwls=New List<Work_Log_Sheet__c>();
for (Work_Log_Sheet__c wls : lwls) {
sid.add(wls.Id);
if(wls.Work_Update_Date__c==System.today()){
wls.Total_Hours__c=wls.Total_Hours__c+wls.Total_Time__c;
lwls.add(wls);
}
}
insert lwls;
}
Note : there is no error . but i am not getting results. How can i write this code.
Thanks in advance
Thulasi.
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.
Trigger :
trigger TimeCount on Work_Log_Sheet__c (before insert, before update) {
decimal count;
Set<Id> sid = new Set<Id>();
List<Work_Log_Sheet__c> lwls=New List<Work_Log_Sheet__c>();
for (Work_Log_Sheet__c wls : lwls) {
sid.add(wls.Id);
if(wls.Work_Update_Date__c==System.today()){
wls.Total_Hours__c=wls.Total_Hours__c+wls.Total_Time__c;
lwls.add(wls);
}
}
insert lwls;
}
Note : there is no error . but i am not getting results. How can i write this code.
Thanks in advance
Thulasi.
so you have Work_Log_Sheet__c object where you have Total_Time__c and Total_Hours__c field right ? can you share your req in detail so I can help you out ...
Above code will not do anything because lwls list is empty as you only initialized and instead of this list you should use Trigger.new in for loop but it would be helpful if you will share the req properly on what condition what you need....
Try the below code this will help you ...
As on same object you want to update the data so DML is not require before insert will do the job...check with above code and let me know if that helps you...
share your req so I can help you and then you can ablove code to handle update case well, as that was only for insert...
First time, I tried with trigger.new, that is not working. That's why, I changed the above code
The above code will work for sure, may be you are missing something...let me know if you are facing any error....
just take this example:
This is trigger on Account, it will simply check whatever field value is there
Current_Provider__c it will add Year__c and show the results...so while inserting if Current Provider is 5 and year is 12 then it will show the 17 after inserting...please check your code and modify accordingly...
thanks