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
Rahul Gautam 6Rahul Gautam 6 

How to use SELECT Query in HTML E-Mail Template

hi
I have a Email Template. I have edited the HTML version of templet and addedd a SELECT Query. This Query will fetch Data from a Custom Object. Custome Object has a Lookup Field on Contact.
When io run the Email Teplate, the SELECT code is diplay as it is. it is not Run.

Do i Need to writ the SELECT Quiery in some brackets? Can someone tell me the syntax for writing SELECT Query in HTML Email Template.

Dear Investors {!Contact.Name} .
<br>

{
Contact cnt =[Select ID From pba__Property__c where Title = 'Test Sale'];
if (cnt.size() > 0 && cnt.get(0).Body != null)
             {             
                 body = cnt.get(0).Body;
                 body = body.replace('#FieldAPIName#', recordValue);
                }
email.setPlainTextBody(body);
}
 
ShekarMSShekarMS
except merge fields, SOQL or any code will not work in HTML Email Teamplates. user VF Email Templates if you need any related objects data to be displayed.
Vijay Singh 105Vijay Singh 105
Hi Rahul,
you create visualforce page and use as new template.