My account trigger has heretofore been firing inside this code block

if( Trigger.isBefore && (Trigger.isUpdate || Trigger.isInsert)){    

    ....code ....    


I've added a block that should run on before insert, to do some manual changes on record fields before they are committed to the database. I've added this:

if(Trigger.isBefore && Trigger.isInsert){
    system.debug('***  BEFORE INSERT');
    Map<String,String> kv_country_reverse = new Map<String,String>();
    List<MappingObject__c> ma = new List<MappingObject__c>([SELECT txtKey__c,txtValue__c from MappingObject__c where txtMapName__c = 'ISOCodeToCountry']);  
    for(MappingObject__c t:ma){
    for(Account a:Trigger.new){
        // inserted from external application as a ISO shortcode, we look up the correct value in a Map and change it before inserting
        a.Country__c = kv_country_reverse.get(a.Country__c);

This later block never executes , even though it should be executed first. The logs doesn't show my debug statement above so nothing is happening. What am I overseeing?

  • Can you post your trigger declaration as well?
    – Jayant Das
    Commented Feb 6, 2019 at 15:49
  • 1
    Debug statements are not a fair assessment if something happened. Could have been omitted because of maximum debug log size, or because of your trace flags. You need to check your code coverage to see if it's being covered (you need unit tests).
    – sfdcfox
    Commented Feb 6, 2019 at 15:52
  • You could also setup a custom debug log level where everything is set to none except for Apex which should be set to DEBUG. This will drastically cut down your debug logs Commented Feb 6, 2019 at 15:53
  • 1
    Hah! of course it was a PEBKAC, my trigger statement was trigger AccountTrigger on Account (before update, after delete, after update,after insert) <--- note that this is missing before insert :) I'm on the right track now
    – akarnid
    Commented Feb 6, 2019 at 16:16
  • @akarnid Glad that you were able to figure it out. I had thought so, and thus asked to post the declaration to cross check, if that was indeed the case. You may like to post the correction as an answer so that this question is marked to be resolved.
    – Jayant Das
    Commented Feb 6, 2019 at 16:18

1 Answer 1


The problem here is that the trigger declaration was missing the crucial before insert

This is the trigger declaration:

trigger AccountTrigger on Account (before update, after delete, after update,after insert) {

Note that the before insert is missing. After adding that the code started to execute.

You must log in to answer this question.

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