You need to sign in to do that
Don't have an account?
insert current date into the custom date field using triggers
Hi All,
I need to insert current date into the date field. Here i am using trigger for that. But, it is not inserting the current date.
Plead check my code and what is the problem in that.
Bellow my code.
Code :
trigger Tmesheet on Work_Log_Sheet__c (before insert, after insert) {
list<Work_Log_Sheet__c > lwls = new list<Work_Log_Sheet__c> ();
for(Work_Log_Sheet__c wls : trigger.new){
wls.Work_Update_Date__c=system.today();
lwls.add(wls);
insert lwls;
}
}
Error :
Tmesheet: execution of BeforeInsert caused by: System.SObjectException: DML statement cannot operate on trigger.new or trigger.old: Trigger.Tmesheet: line 7, column 1
Thanks in advance
Thulasi
I need to insert current date into the date field. Here i am using trigger for that. But, it is not inserting the current date.
Plead check my code and what is the problem in that.
Bellow my code.
Code :
trigger Tmesheet on Work_Log_Sheet__c (before insert, after insert) {
list<Work_Log_Sheet__c > lwls = new list<Work_Log_Sheet__c> ();
for(Work_Log_Sheet__c wls : trigger.new){
wls.Work_Update_Date__c=system.today();
lwls.add(wls);
insert lwls;
}
}
Error :
Tmesheet: execution of BeforeInsert caused by: System.SObjectException: DML statement cannot operate on trigger.new or trigger.old: Trigger.Tmesheet: line 7, column 1
Thanks in advance
Thulasi
Please let us know if this will help you
All Answers
It's working perfect. But, After insert is not required.
Please let us know if this will help you
You can seperate logic as below,