I have a trigger to create a new Opportunity when a field on my Custom Object is changed, but it doesn't seem to be creating the new Opp. There are no errors, the new Opp is simply not created. I realize that it should only fire after update and not on insert.... What am I missing?

trigger MDwinning on MD_Meeting__c (after update) {
List <Opportunity> oppToInsert = new List <Opportunity> ();
for (MD_Meeting__c m : Trigger.new) {
    if (m.SD_Action__c=='Sales Accepted Lead') {    
    Opportunity o = new Opportunity ();   
    o.OwnerId = m.Sales_Director__c;
    o.Name = m.Name;
    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;
    }//end if
}//end for o
try {
    insert oppToInsert; 
} catch (system.Dmlexception e) {
    system.debug (e);
  • Have you tried adding system.debug to verify the value of SD_Action__c?
    – Mike Chale
    Jan 22, 2014 at 21:34
  • I have not. I just changed the if statement to a boolean checkbox and it yields the same result, or lack thereof. Jan 22, 2014 at 21:55
  • As a test, comment out the try/catch and just leave the insert oppToInsert; at the end of the trigger. Jan 22, 2014 at 22:56

1 Answer 1


Remove the try-catch to see the fireworks (it's only in development environment, right? It's not like you'll cripple the ability to update meetings for all users). Or enable debug logging.

I suspect you're not setting Stage (StageName) and that's what is blocking the successful insert.

Once you have nailed & fixed it you might decide to either put try-catch back or use Database.insert(oppToInsert, false); - it'll try to save what it can.

P.S. Have you had a look at Summer'13 Chatter Action buttons?

  • A-ha! I can now see some information in the debug log. Update failed. First exception on row 0 with id a0r40000005N1WKAA0; 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: [] Jan 23, 2014 at 0:17
  • You probably have some loop. update meeting -> insert opportunity -> trigger there trying to update all related meetings... You'll have to either change the meaningful part of that trigger's logic or simply use some static flags to not enter there (similar to how we deal with recursive triggers' problem)
    – eyescream
    Jan 23, 2014 at 7:16
  • All the errors are gone from the trigger, but it still won't fire. Debug log lists "<none>" as the operation. Jan 23, 2014 at 12:35
  • So it's straightforward insert oppToInsert; (without try-catch), the condition is met, list isn't empty and it doesn't fail but also doesn't insert? Very weird. Blank debug log might indicate you modified your filter settings, try to reset them to normal levels?
    – eyescream
    Jan 23, 2014 at 12:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .