In this article, we are going to see some advanced concepts of the Draw Loop with Salesforce integration.
- SOQL query in draw loop:
Generally, in draw loop we can merge the Salesforce record fields related to only the main object where we created DDP (Dynamic Document Package). To resolve this issue, we can use SOQL query in draw loop to fetch unrelated record or all child records.
Steps to create SOQL query:
- Once the DDP record is created in Salesforce, click the ‘New Relationship’ button in the relationship section.
- Select Type as SOQL Query and write the SOQL query as to which record you want to fetch in SQOL field. Select Copy Type as row if you want to display list of records. Give any name to Relationship Alias to refer in field tagger.
- In Field tagger, we can refer the field which is returned by the SOQL query; so, click Field tagger in DDP record.
- Here, we can select the fields we want to merge in the document and place that tag to word document.
- To display records in table:
- Create a table in word document to display list of Salesforce record as shown below:
- Just two rows are enough to display all records dynamically based on the SOQL Query. One for displaying the title for the column and another for displaying records dynamically. In field tagger, there is a tag available as below. <<Parentguardians_Start>>, <<Parentguardians_name>>, <<Parentguardians_Type>>.
- These tags will have prefix with the field name we queried by SOQL. That prefix is taken from the name we used while creating the relationship record in the SOQL query in the field of Relationship Alias.
- The table size will be increased dynamically based on the number of records returned by the query. We don’t need to worry about the size of table.
- Dynamic image in word document:
We can display the Salesforce record image in a word document dynamically by using draw loop. The image should be public site URL in the Salesforce record field.
- Add a Rich Text field to an object
- Add an image to a record
- Configure the template
- Generate documents
- We need to create the rich text filed in Salesforce object to store the image in the record. After creating the field, add the image to the Salesforce record. In the Salesforce side, we have done the process to display the image. Now, we need to configure the template (Word Document) used in the draw loop to generate the dynamic document.
- Create the place holder in the word document to display the image and add sample image to the template. This image will be replaced by the Salesforce record image dynamically. The draw loop will automatically resize the place holder based on the image from the Salesforce record.
- In selection area, double-click the reference to the placeholder image, paste the tag from your clipboard, then edit the tag to include __image inside the angle brackets.
Using Draw Loop, we can use SOQL query to fetch all child records as well as un related records to display in word document dynamically. We can use a table to display list of Salesforce record in table and can display the image dynamically.