Sputnik Moment Logo Final

Re-Parenting Records and What It Does to Workflows

workflowWorkflows are an essential part of Salesforce but if we’re not careful Workflows can also cause quite a bit of grief; for example if emails accidentally get sent out when they shouldn’t be.  This would be especially bad if the rogue emails contained false information that led a Contact to believe they were receiving a large amount of grant money, or some other equally disastrous bit of misinformation.  For the most part this is easy to avoid, but there is one quirk of Salesforce that can create exactly this kind of disaster without even seeming to fit Workflow criteria.  Lucky for you I’m going to show you how this can happen and exactly how to avoid it.

The core of this quirk is something called a “re-parentable foreign key relationship”.  You don’t actually need to remember this name or even know what it means but the quick version is that every link in Salesforce to another Salesforce record is a “foreign key relationship” and some of these relationships are built standard into Salesforce – for example the Organization Name field on Gifts.  If you can change the link after creating a record, ex. changing the Organization Name field on a specific Gift (keep this example in mind) then it is “re-parentable”.  Also note that this can apply to both Standard and Custom Objects.

The problem is that anytime the parent field (the Organization Name field in our previous example) is changed then the system treats the child (the Gift in our example) as a new record and will activate any workflows set to activate whenever a new record is created.  See the screenshots below for a detailed example as well as an explanation on to how to avoid falling into this trap.


  • I create a workflow that will activate whenever an Opportunity (aka Gift) is created or edited to meet the criteria listed (Send Congratulations Email to Contact EQUALS True)

image 1image 2


  • And here I’m about to save a new Opportunity which happens to meet our Criteria.

image 3


  • Checking our time based workflow queue shows a newly created workflow which I will immediately delete (I don’t actually want to send an email to myself)

 

image 4


  • The scheduled email has been deleted

image 5


  • Now I edit the newly created Opportunity and change the ‘Account Name’ (sometimes renamed ‘Organization Name’) field and then…

 

image 6


  • The scheduled email has come back from the dead waiting to be sent out again!  Note that this would send an email out immediately if I hadn’t chosen to use time delayed Workflows for this example.

 

image 7


So how do we keep this from happening?

  • First we’re going to create a new checkbox on the Opportunity object.  This field won’t be on a page layout so name it anything you want, I named it ‘Prevent Workflow Activation’

image 8

 


  • Add an extra criteria to your Workflow stating that the new checkbox field must be false for the Workflow to activate

image 9


  • And then add a field update to the Workflow so that the first time the Workflow activates it will change the criteria such that it can never activate again.

image 10


  • And now your Workflow will not come back to haunt you ever again!

image 11

So there you have it, this is a surefire way to keep this weird and often overlooked aspect of Salesforce from activating Workflows when your back is turned.  Ideally Salesforce would give you the option when creating a Workflow to specify if it should trigger when reparenting a record but until then this is going to be the best solution available.  One last point:  this only works for a single Workflow, if you have multiple Workflows which could fall victim to this quirk then you will have to create a separate check box for each and every Workflow.

About Re-Parenting Records and What It Does to Workflows

workflowWorkflows are an essential part of Salesforce but if we’re not careful Workflows can also cause quite a bit of grief; for example if emails accidentally get sent out when they shouldn’t be.  This would be especially bad if the rogue emails contained false information that led a Contact to believe they were receiving a large amount of grant money, or some other equally disastrous bit of misinformation.  For the most part this is easy to avoid, but there is one quirk of Salesforce that can create exactly this kind of disaster without even seeming to fit Workflow criteria.  Lucky for you I’m going to show you how this can happen and exactly how to avoid it.

The core of this quirk is something called a “re-parentable foreign key relationship”.  You don’t actually need to remember this name or even know what it means but the quick version is that every link in Salesforce to another Salesforce record is a “foreign key relationship” and some of these relationships are built standard into Salesforce – for example the Organization Name field on Gifts.  If you can change the link after creating a record, ex. changing the Organization Name field on a specific Gift (keep this example in mind) then it is “re-parentable”.  Also note that this can apply to both Standard and Custom Objects.

The problem is that anytime the parent field (the Organization Name field in our previous example) is changed then the system treats the child (the Gift in our example) as a new record and will activate any workflows set to activate whenever a new record is created.  See the screenshots below for a detailed example as well as an explanation on to how to avoid falling into this trap.


  • I create a workflow that will activate whenever an Opportunity (aka Gift) is created or edited to meet the criteria listed (Send Congratulations Email to Contact EQUALS True)

image 1image 2


  • And here I’m about to save a new Opportunity which happens to meet our Criteria.

image 3


  • Checking our time based workflow queue shows a newly created workflow which I will immediately delete (I don’t actually want to send an email to myself)

 

image 4


  • The scheduled email has been deleted

image 5


  • Now I edit the newly created Opportunity and change the ‘Account Name’ (sometimes renamed ‘Organization Name’) field and then…

 

image 6


  • The scheduled email has come back from the dead waiting to be sent out again!  Note that this would send an email out immediately if I hadn’t chosen to use time delayed Workflows for this example.

 

image 7


So how do we keep this from happening?

  • First we’re going to create a new checkbox on the Opportunity object.  This field won’t be on a page layout so name it anything you want, I named it ‘Prevent Workflow Activation’

image 8

 


  • Add an extra criteria to your Workflow stating that the new checkbox field must be false for the Workflow to activate

image 9


  • And then add a field update to the Workflow so that the first time the Workflow activates it will change the criteria such that it can never activate again.

image 10


  • And now your Workflow will not come back to haunt you ever again!

image 11

So there you have it, this is a surefire way to keep this weird and often overlooked aspect of Salesforce from activating Workflows when your back is turned.  Ideally Salesforce would give you the option when creating a Workflow to specify if it should trigger when reparenting a record but until then this is going to be the best solution available.  One last point:  this only works for a single Workflow, if you have multiple Workflows which could fall victim to this quirk then you will have to create a separate check box for each and every Workflow.