[SalesForce] How to tell if this trigger is firing

I'm a newbie here, and this is my first trigger.

This is a trigger which was given to me on here. It is in a sandbox in my organization. It 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.

Best Answer

The Subsidiaries_On_Contract__c field needs to be populated and in addition have some values separated by a comma.

Eg abc,def

The code is trying to split based on the comma and creating a record for each part.

So check that the Subsidiaries_On_Contract__c field is populated.

You can set up debug monitor using Setup > Monitoring > Debug Logs

Add the name of the executing user, perform the save, and then come and look at the debug logs to see if there is any activity. (Worth adding some debugs in the trigger to print out say Subsidiaries_On_Contract__c - so System.debug('Subsidiaries_On_Contract__c ' + newContract.Subsidiaries_On_Contract__c); within the for loop)

Related Topic