I have an odd problem. A trigger was creating a record which failed to insert due to workflow field update being too long for the field. The error did appear in error log, but did not in the standard UI.
Here's code excerpt:
trigger cloneElecAMsignOff on Electricity_Meter__c (before update) {
RecordType elecRT = [select Id from RecordType where Name = 'Elec' and SobjectType = 'Electricity_Meter__c' limit 1];
List<Electricity_Meter__c> myList = new List<Electricity_Meter__c>();
for(Electricity_Meter__c a: trigger.new) {
if (
a.Account_Manager_Sign_Off_Date_Time__c != Null &&
a.Clone_Date_Time_Stamp__c == Null &&
a.RecordTypeId==elecRT.Id &&
(
a.Deal_Done_Not__c == 'Deal Done (Existing client / Existing meter)' ||
a.Deal_Done_Not__c == 'Deal Done (New Meter, New Client)' ||
a.Deal_Done_NOt__c == 'Deal Done (New Meter, Existing Client)' ))
{
a.Clone_Date_Time_Stamp__c = System.Now();
Electricity_Meter__c b = new Electricity_Meter__c();
b.Name = a.Name;
myList.add(b);
}
try {
insert myList;
} catch (system.Dmlexception e) {
system.debug (e);
}
}
How do I ensure that:
1) The user gets error message.
2) a.Clone_Date_Time_Stamp__c = System.Now();
is not commited to the database.
Many thanks