Preparing a Mail Merge document
I am not sure there is a bigger time-sink in Salesforce than preparing Mail Merge documents. (Nope, not even Email Templates - with Mail Merge you have the extra hassle of dealing with the documents).Â
I'm just concentrating on Word documents here but you can do really cool things with Excel, Powerpoint or even Google Docs. Â
Steps to create a mail merge document:
- Create the shell of your document, have an idea where you want the fields to go. Types of fields you may have in your Word document.
- Fields directly from the record in Salesforce
- Fields from related records in Salesforce
- Formulas on the record in Salesforce
- Image fields from documents uploaded to Salesforce
- Paragraphs of text that are conditional in Word depending on a field in Salesforce
- More advanced word fields
- Create any formula fields on the main Object in Salesforce
- This is a balancing act - do you want the logic in the Word document or in Salesforce. I think have all the logic in Salesforce and the end result in Word.Â
- Eg you need a clause to appear in Word if the Type is A, B or C.Â
- Create a formula field in Salesforce named TypeClause
- I ALWAYS add a note in the Description field to note that this field exists only for the Merge Documents - eg CONGA or MERGE
- Type = Checkbox
- Formula OR(ISPICKVAL(Type,"A"),ISPICKVAL(Type,"B"),ISPICKVAL(Type,"C))
- Add a Word Field to your document (ctrl +F9)
- IF <<TypeClause>>="True" "The contents of your para" "" (ensure you enter TypeClause correctly depending on which app you are using.Â
- Create a formula field in Salesforce named TypeClause
- Eg you need a clause to appear in Word if the Type is A, B or C.Â
- This is a balancing act - do you want the logic in the Word document or in Salesforce. I think have all the logic in Salesforce and the end result in Word.Â
- If using Conga, create a Report Type to include all the related fields that you want to use. Custom Report Types are way more useful than creating formula fields for every related field you want to include on your merge document.
- Or use SOQL Queries - they are more robust, less prone to people modifying them or deleting them, and you need Queries if you are working with Partner or Customer communities documents.Â
- If using Drawloop, set up the relationships in the Loop setup screen for all the related Objects.
- Create documents records for your images, and then add the image URLs to fields on the record.Â
- Eg you want a conditional logo to appear on the document based on what product it is.Â
- In the product object, add a new field for image file.Â
- Add the externally valid URL to the image file field.Â
- Add that image field to your Report Type (Conga).Â
- Add the image field into your word document (it's different syntax for Conga or Drawloop).Â
- Ensure that the image size is the exact size to fit within the margins of your word document.Â
- Eg you want a conditional logo to appear on the document based on what product it is.Â
- Add all the correct Merge fields into your document
- I like colouring all the fields until the document is complete (yep, it is blurred out).Â
- If using Drawloop, upload your template, if using Conga, you can test before you upload your template.Â
- If using Conga, create your button.Â
- If using Drawloop create your Loop setup and your button.Â
- Set up the record in Salesforce to have all the test data in it
- Test Test and Test again.Â
- Test with different Salesforce recordsÂ
- Rinse and repeat!Â
Merge Field Tricks
A snippet of the above document.Â
Note Show Field Codes and Show Formatting Marks are turned on - DO NOT TRY TO WORK WITH MAIL MERGE DOCUMENTS WITHOUT THESE SETTINGS TURNED ON!
Note the extensive use of Word IF Fields.Â
Basically I set up a checkbox field or formula in my object to determine if a section of text should display on the document.Â
I use Word Fields to say should this text be shown. Then other field within the merge field that will be displayed.Â
Note that the Word Merge Fields are joined together with no break, and the line breaks are within the merge field. This ensures no gaps in your content document when it displays. It is easier to deal with each field on it's own line first, then smoosh all the fields together.Â
Modifying the Mail Merge document
You are testing, and you found that you just need one conditional merge field to create an extra paragraph of text in the Word document. This is where the time sink starts.Â
Conga
- Navigate to the object that you need to create the formula field on.
- Create the formula field.Â
- Make the field visible,Â
- Ensure the field is showing the right value for the right conditions.Â
- Go to the main record that you are testing.
- Click the Conga button to get to the template builder.Â
- Oops, you forgot. It needs to be on the Report Type because it's in a related object from your main object.Â
- Note this part may be replaced with modifying the SOQL query, but it is just as annoying.
- Go to Report Types
- Modify the Report Type to include the new field.Â
- Place the new field into the right section on the report type.Â
- Change the name of the field on the Report Type to make more sense
- Save the report Type.Â
- Go to the ReportÂ
- Drag and drop the new field onto the report.Â
- Save the report.Â
- If you want to test the report at this stage, then
- Modify the report criteria to bring back a valid record, rather than an empty parameter.Â
- Run the report
- Be sure you don't save the report this time.Â
- Go to the main record that you are testing.
- Click the Conga button
- Wait about a minute for the Conga popup window to go through all it's configuration
- Click Tools & Settings
- Click Template BuilderÂ
- Wait about a minute for Conga to display the Template Builder window.Â
- Pfaff about in the template builder window to find the field you added to your Report Type.
- (or download the View Data workbook, but then you give up using that because it puts spaces at the end of the field name when you paste it into Word and you have to type the 4 braces yourself, whereas the copy from the template builder puts both sets of braces in and puts a space AFTER the field so you can quickly add new fields). Â
- Click on the Copy button (you have given up using the drag and drop feature because it is so cumbersome and is only useful for table data).Â
- Open your Word documentÂ
- View field codes (alt+F9)
- Find the location you want to put the new field.Â
- Paste the new field in.Â
- Save your word document.Â
- Go back to the template builder.Â
- Click the back button (why oh why oh why can't you have both open at the same time!).Â
- Choose Local Template Tab
- Click Select File
- Browse to your file you just saved.Â
- Click Open
- Click Preview
- Wait about a minute for Conga to merge and download the document.Â
- Open the document from the downloads tab at the bottom of your browser.Â
- Click Enable Editing
- Turn off view field codes (alt +F9)
- Find the field that you just added.Â
- Let out a muffled scream when you realise it's not quite right and you have to start the whole process all over again.Â
- Find about 10 other errors in the document that you are yet to fix.Â
- Rinse and repeat, oh about 1000 times until you get it right.Â
- Then test it as the user who needs to run it to find out that they can't run it or the field is not visible for them.
- Go into profiles and update profiles so that user can see the field.Â
Drawloop
- Navigate to the object that you need to create the formula field on.
- Create the formula field.Â
- Make the field visible,Â
- Ensure the field is showing the right value for the right conditions.Â
- Go to the DDP in the Loop app that you need to modify.Â
- Click on the document name to open up the document record
- Download the Word file related to that DDP
- On the DDP record, open the Field Tagger
- Find the field in the field tagger
- Open your Word documentÂ
- Find the location you want to put the new field.Â
- Paste the new field in.Â
- Save your word document.Â
- Go back to the document record
- Click Replace Document
- Upload the document. (Noting that if any automated documents go out at this time they might be incorrect because you are modifying a document in a live environment and there is no other way to test it other than create a whole new DDP).Â
- Go to the main record that you are testing.
- Click the LOOP button
- Choose the download option (ensure you have a download option in your LOOP setup just for this occurrence)
- Wait quite a few mins for the download to occur.Â
- Open the generated document.
- Find the field that you just added.Â
- Let out a muffled scream when you realise it's not quite right and you have to start the whole process all over again.Â
- Find about 10 other errors in the document that you are yet to fix.Â
- Rinse and repeat, oh about 1000 times until you get it right.Â
- Then test it as the user who needs to run it to find out that they can't run it or the field is not visible for them.
- Go into profiles and update profiles so that user can see the field.Â
Â
Â
Â