Working with Child Relationships

Salesforce supports master-detail relationships and we’ve given you the ability to use those relationships in WebMerge Mappings.

To use Child Relationships, you will need to create a loop in your document that supports iterating over a list of data. To do so:

 

{foreach from=$Contacts item=_contact}
   {$_contact.Name}
   {$_contact.Phone}
{/foreach}

 

The "_contact" part of this loop is the local variable that you'll use inside the loop.  To print out a field value, you use {$_contact.FIELD}, where FIELD is the Salesforce API Field Name for the sub field on that object (ie Name, Favorite_Color__c, etc).

In your Salesforce WebMerge Mapping you will now have the ability to map a Salesforce field or relationship to "Contacts". When working with child relationships, we’re going to ignore the _contact field in this situation because it is the iterator. Let’s instead look at Contacts and in the Salesforce Field section, find the relationship you want to map to the list.

 

salesforce_child_relationship.png

In this example, we will use Child Relationship: Contacts. This will allow you to create a WebMerge generated document that iterates over all the child contacts attached to a Salesforce record and output their Name and Phone Number.

Create a Table

If you'd like to create a table in your document, you can do that use a "tablerow" tag instead of the "foreach" loop like this:

Name Phone Number
{tablerow from=$Contacts item=_contact}{$_contact.Name} {$_contact.Phone}{/tablerow}
Have more questions? Submit a request

6 Comments

  • Avatar
    Robby Johnson

    so what would the Webmerge Mappings in SF look like for the child relationship fields above? thanks

  • Avatar
    Jeremy Clarke

    Hi Robby,

    In Salesforce, you could see a field for "Contacts" and then you would map that field to "Child Relationship: Contacts"

  • Avatar
    Shawn Thornley

    Is there any way to make this work with Lookup relationships? For example having {$Contacts.0.Manager__r.Name} or similar on a fully custom object. I have tried and it doesn't appear to output anything. {$Contacts.0.Name} however does work no problem.

  • Avatar
    Jeremy Clarke

    Hi Shawn,

    Please turn on Debug Mode (https://support.webmerge.me/hc/en-us/articles/206526126-Debug-Mode) and you'll be able to see the data we're receiving from SF and the correct subfields to use for the referenced objects.

    If you have any troubles, please create a support ticket and we'll help you from there.

    Thanks!

  • Avatar
    Steve Jones

    Is it possible to go down multiple layers? E.g. Account -> Opportunities -> OpportunityLineItems.

  • Avatar
    Jeremy Clarke

    Hi Steve,

    Yes! There should be an option in your mapping settings called "Child Relationship: Opportunities.OpportunityLineItems" --- this will send over a list of the line items grouped by opp.

    Here's an example loop

    {foreach from=$LineItems item=_items key=_oppId}
    {foreach from=$_items item=_item}
    {$_item.Name} - {$_item.Total}
    {/foreach}
    {/foreach}

Please sign in to leave a comment.
Powered by Zendesk