I have an email template which uses merge fields from a custom object. For reasons difficult to explain here, I have to write my own code to read the body of the email template in Apex, replace merge fields with the objects field value. For eg:
plainTextBody.replaceAll('{!File_User__c.Name}', fileUser.Name);
However, this throws an exception
System.StringException: Invalid regex: Illegal repetition {!File_User__c.Name}
I search on the net and the resolution is to escape the curly braces. I have tried using \{!File_User__c.Name\} but it doesn't work.
My questions are 1. How to we parse merge fields without the error above? 2. Is there a better way of parsing email template?
Thank you.