Activity Forums Salesforce® Discussions Can we add grandchild data in a single document with Salesforce Apex code using Webmerge?

  • Adarsh

    Member
    March 22, 2018 at 8:20 am

    Hi Neha,

    Document for child records using webmerge

    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:

    Sample Code :

    {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}.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.

    Document for grandchild records using webmerge

    According to a acticle from webmerge support team, it may possible. If you need to loop through child records within your child relationships, Salesforce will send over a list of records indexed by the Id of your main child record.  You can do something like this in your document.

    sample code :

    {foreach from=$Contacts item=_contact}
    {$_contact.Name}
    {foreach from=$Dependents[$_contact.Id] item=_dep}
    - {$_dep.Name}
    {/foreach}
    {/foreach}

    You'll then need to update your Salesforce Mapping and map the "Dependents" field to "Child Relationship: Contacts.Dependents".

    Hope it helps 🙂

  • PRANAV

    Member
    March 23, 2018 at 11:07 am

    Hi

    The above functionality really helps alot.

    Can we also send the documents to the child and grandchild record via WebMerge? Please let me know.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos