This question is related to a previously answered question: Trigger won't Fire
It looks like my organization has an existing test class that isn't playing nicely with my new Trigger. Could someone please help me get rid of the error. I think it's because another trigger has the record open and I'm trying to do something else with it? Any insight is greatly appreciated.
Here is the error:
System.DmlException: Update failed. First exception on row 0 with id a0r40000005MyUPAA0;
first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, MDwinning: execution of AfterUpdate
caused by: System.FinalException: Record is read-only
Trigger.MDwinning: line 4, column 1: [] MDMeetingcStatsTT.cls /src/classes line 13
The test class that was there for a different trigger is here:
@isTest
private class MDMeetingcStatsTT {
static testMethod void testTrigger() {
try {
MD_Meeting__c o = new MD_Meeting__c();
insert o;
System.assertNotEquals(null, o);
}
catch(Exception e) {
List<MD_Meeting__c> l = [SELECT Id from MD_Meeting__c LIMIT 1];
update l;
System.assertNotEquals(null, l);
}
}
}
And here is my trigger that (thanks to user @eyescream) includes all the required opportunity fields:
trigger MDwinning2 on MD_Meeting__c (after update) {
List <Opportunity> oppToInsert = new List <Opportunity> ();
for (MD_Meeting__c m : Trigger.new) {
if (m.SAL__c=True) {
Opportunity o = new Opportunity ();
o.OwnerId = m.Sales_Director__c;
o.Name = m.Name;
o.StageName = 'Generate Opportunity';
o.Market_Developer__c = m.Market_Developer__c;
o.AccountId = m.Account__c;
o.Type = 'Sales - New Business';
o.CloseDate = System.Today()+150;
o.MeetingLookup__c = m.Id;
oppToInsert.add(o);
}//end if
}//end for o
//try {
// insert oppToInsert;
// } catch (system.Dmlexception e) {
// system.debug (e);
// }
}