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.

  • You say "at the time the parent is saved", although in this case it's an insert trigger so will only work the first time the record is created. If you're modifying an existing record then this trigger won't fire. Just a thought.
    – Doug B
    Commented Mar 21, 2013 at 17:05

2 Answers 2


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)

  • Thank you very much for your input. The record I am using for this has multiple values in Subsidiaries_On_Contract__c. I'm reading over the logs. I only see the VF pages code, but I don't see the trigger kicking off in the log, but I may not have the Debug logs set properly. I tried running the trigger in the Dev Console as @nivyaj suggested and I got this error : "line 1, column 0: required (...)+ loop did not match anything at input 'trigger'". Any ideas on that ? Thank you very much for your help. I really appreciate it.
    – Zoom_v
    Commented Mar 21, 2013 at 17:56

The developer console is a handy debugging tool, and doesn't have the limitations of the drbug logs. it gives you the debug logs as you're stepping through actions plus more.

  • Ok - I finally figured it out. There was a validation rule which was preventing the trigger from kicking in. Thank you very much for your help @techtrekker and nivyaj. I really appreciate it !
    – Zoom_v
    Commented Mar 21, 2013 at 18:50
  • NP. There's an order of execution when it comes to operations in salesforce. This outlines what gets fired when salesforce.com/us/developer/docs/apexcode/Content/… Commented Mar 21, 2013 at 19:02

You must log in to answer this question.

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