Activity › Forums › Salesforce® Discussions › Can we add grandchild data in a single document with Salesforce Apex code using Webmerge?
Tagged: Content Document, Document, Document Management, Document Object, Grandchild Data, Grandchild Field, Grandchild Relationship, Salesforce Apex, Salesforce Apex Class, Salesforce Apex Code, Salesforce Apex Controller, Salesforce Apex Function, Webmerge
-
Can we add grandchild data in a single document with Salesforce Apex code using Webmerge?
Posted by Neha on March 22, 2018 at 6:14 AMCan we add grandchild data i.e (child’s child data) in a single document with Apex code using Webmerge?
PRANAV replied 8 years, 1 month ago 3 Members · 2 Replies -
2 Replies
-
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 🙂
- [adinserter block='9']
-
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.