If you’ve ever got this error when generating a document, you probably have less hair than you did before generating the document.
There are multiple reasons this could happen:
- HTML tags in a Quote Line Line Column field in the lines section Template Content.
- One of your HTML Template Content records has a reference to an image that has a bad SRC (does not exist, unable to load, no permission to access the image, etc).
- The markup inside your Custom VisualForce Page Template Content is bad. Below is a list of supported tags per this Salesforce article.
- Supported HTML Tags
- Supported HTML Tag Attributes
- Supported HTML Tags
HTML tags in a Quote Line Line Column Field
You have a standard lines section. You have a list of Line Columns on your Quote Template. One of those Line Column fields on one or more of your Quote Line records on the offending Quote has a value that contains HTML tags. A frequent culprit of this is the Description field. It could also be some custom field you made and pulled into your template via a Line Column.
The Image Thing
You might have some HTML referencing an image that no longer existed or become corrupt (the url for the image just shows a blank page or some other corrupt image URL). Example:
<img alt="logo" height="100" src="https://mydomain--c.naXX.content.force.com/servlet/servlet.ImageServer?id=0151K0000040ptM&oid=00D41000000FWOw" width="180" />
What to do? Create a new image and update the HTML to use the new URL.
Also! Do you have a Logo Document ID set on your Quote Template? Check the document record for that ID and make sure it has Externally Available Image set to TRUE.
Custom VisualForce Page Template Content
The markup of the content is bad. You have to go in and make sure that all tags that are non -apex tags are not HTML but XSL:FO instead.
Sometimes, when displaying rich text fields (such as Product Description) in a VisualForce Page Template Content, HTML tags are in the rich text. But you can not have HTML tags.
What to do? Put this in your controller:
// do this to replace all html tags in a rich text field.
richTextFieldValue = richTextFieldValue.replaceAll('<[^>]+>',' ');
Thanks to Ashley for her input on this article!