function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

How can I tell if this trigger is firing ?

This is a trigger which is meant to create child records based upon a multi-value field in a parent record at the time the parent is saved. It doesn't seem to be creating the records upon being saved :

trigger AutoCreateSubs on Contract_Overview__c (after insert) {
 List<Subs_Serviced_On_Contract__c> subs = new List<Subs_Serviced_On_Contract__c>();

    //For each position processed by the trigger, add a new  

    //Subs_Serviced_On_Contract record for the specified Subsidiaries_On_Contract__c.  

    //Note that Trigger.New is a list of all the new positions  

    //that are being created.  

    for (Contract_Overview__c newContract : Trigger.New) {
        if (newContract.Subsidiaries_On_Contract__c != null) {
            // split out the multi-select picklist using the semicolon - or comma -delimiter
            for(String subsoncontract: newContract.Subsidiaries_On_Contract__c.split(',')){
                subs.add(new Subs_Serviced_On_Contract__c(
                        Name = newContract.Id,
                        Contract_Overview__c = newContract.Id,
                        Subsidiary_Name__c = (Id)subsoncontract,
                        Logo_Usage_Allowed__c = 'Yes'));
    insert subs;



The trigger is at 100% code coverage and is Active. There is a value in the Subsidiaries_On_Contract_c field, so that wouldn't be preventing it from firing off.

Does anybody see anything wrong with this code which would prevent it from creating the records ? I'm not sure if it is error-ing out or not even firing off. Can somebody give me some direction on this ?

Thank you very much for your help.







There's still a lot of wiggle-room for things to go wrong-


Does the debug log say anything?


Is Subsidiary_Name__c required?  If so, and subsoncontract is null, you'll get no data.


There's still more that can happen, but I'd still ckeck the debug logs and put System.debug()

statements in and around your code - right now you don't know if the problem is the

trigger isn't firing or the records aren't being inserted.




Thanks for catching the fault in the Subsidiary_Name__c line. (it's not a req field).  I changed the line to this : 

Subsidiary_Name__c = subsoncontract,

...or should it have been ?



I'm looking at the debug log and I can't see it firing off the trigger, but I may have a setting wrong. I set the trigger's Apex log filters to Finest, in order to see the most possible.

I ran the trigger in the developer console and I'm getting this error :


"line 1, column 0: required (...)+ loop did not match anything at input 'trigger'"


Thank you very much for your help.


I'd second the suggestion to add some debug statements in there. Preferably after each potential fork or logic check. Just inside the for loop, after the if statement, etc.

Debug out the values of the things you are check to verify that they have the values you expect.

Ok - it looks like a validation rule was preventing it from running. Thank you very much for your help SF & David. I really appreciate it !


Aha - a validation rule.

Good work on finding it in the debug log.


Just FYI:

In the future, also watch out for workflow rules that update fields -

Those happen after triggers, but it can leave you scratching your head about what happened :-)