function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
prakashedlprakashedl 

MSWord Template based doc generation from Apex

I need to generate a word doc/PDF based on MS word template. It is very similar to the use case of mail merge templates where i create word template using SF merge fields. However, I understand that mail merge works only in Internet Explorer browsers. I would like the functionality to work across all browsers. Is there a suggestion to get that working on all browsers? On click of a button on a detail record, I would like to generate a word document based on template with values from the detail record I clicked the button.

 

Any suggestions or pointers would be very useful.

Best Answer chosen by Admin (Salesforce Developers) 
sfdcfoxsfdcfox

You can request Extended Mail Merge from salesforce.com Technical Support. This feature does not yet support DOCX (Word 2007) templates, but does support older versions of Word documents (DOC format). Using this feature will disable the ActiveX control and instead perform the mail merge on the server instead of the client. You can have the generated document emailed to your users and also stored on the Documents tab. However, this behavior still would not happen automatically in Apex Code. I would suggest at looking at Conga Merge or Print Anything as alternative solutions. Obviously, you could write your own application to handle this, but it would likely be far more complex than the results would be worth, unless you were planning on licensing out the application when you were done.

All Answers

sfdcfoxsfdcfox

You can request Extended Mail Merge from salesforce.com Technical Support. This feature does not yet support DOCX (Word 2007) templates, but does support older versions of Word documents (DOC format). Using this feature will disable the ActiveX control and instead perform the mail merge on the server instead of the client. You can have the generated document emailed to your users and also stored on the Documents tab. However, this behavior still would not happen automatically in Apex Code. I would suggest at looking at Conga Merge or Print Anything as alternative solutions. Obviously, you could write your own application to handle this, but it would likely be far more complex than the results would be worth, unless you were planning on licensing out the application when you were done.

This was selected as the best answer
prakashedlprakashedl

Thanks a lot @sfdcfox. I shall try your options and update this post shortly.

prakashedlprakashedl

Is there a way to invoke mail merge or extended mail merge from apex class?

sfdcfoxsfdcfox

You won't be able to trigger merges from a trigger, unfortunately. Every mail merge app I've seen depends on Visualforce or client (aka browser or desktop application) interaction. You would have to be willing to process an XML template and perform a merge of the fields in the XML template in order to generate a document through a trigger.