1

I apologize in advance for the simple question, but I have been having difficulty figuring out how to built this out.

My goal is that once a particular list field on my Account object is updated to a specific choice, it will trigger the creation of a child custom object and link said child object to the master Account.

I first was hoping to achieve this via workflow as the particular field update already has some workflow rules on it, but it appears that I need to utilize an Apex trigger. If not, please correct me.

Any insight/help is greatly appreciated!

2
  • If you want to create a new record off of it I believe you will need a trigger.
    – dphil
    Dec 3, 2014 at 19:29
  • We've done this using Workflows, so a trigger isn't 'required'. In our case, we have a button on opportunity that starts the flow, information from the opportunity, and then creates a 'sub-account' record, which is also a child of account. Works swell!
    – HomerJ
    Dec 3, 2014 at 20:09

2 Answers 2

1

The answer is that you will need a trigger to create new related/child record. At least until the new process builder is GA which has the ability to create related records.

0

A basic form of the trigger (that allows multiple child objects to be created if the field is set to the specific value multiple times from other values) would be:

trigger MyTrigger on Account (after insert, after update) {
    Child__c[] inserts = new Chil__c[] {};
    for (Account a : Trigger.new) {
        if (a.Field__c == 'Magic Value') {
            Account old = Trigger.oldMap.get(a.Id);
            // Only act if the specific field has changed
            if (a.Field__c != old.Field__c) {
                inserts.add(new Child__c(Account__c = a.Id));
            }
        }
    }
    insert inserts;
}

You must log in to answer this question.

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