I have apex code that sends out emails using templates. The code sets the RelatedTo id as a contact, and the WhatID as a custom object which is a child of contact. Sometimes the child object is a child of the RelatedTo object, and sometimes it's not.
When I test the merge fields for the email template, it works correctly, but when the email actually gets sent out, if there is no child object for the related to object, the merge fields are null. I really need the merge fields to be pulled from the child object (which is referenced by the WhatID), even if it is a child of a different contact.
Is there any way for me to accomplish this?