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
RadheyShyam GuptaRadheyShyam Gupta 

How to populate merge variable (e.g.{!Case.SuppliedName}) in Template when I have a template after querying from EmailTemplate

How to populate merge variable (e.g.{!Case.SuppliedName}) in Template when I have a template after querying from EmailTemplate . Actually want to send this Email Template with populated values  in a String to send http request while Integrating Sendgrid Email web Service in Salesforce.Please Suggest me .

Thanks.
Jitender  PaddaJitender Padda
Well, you could create a Component and add it to your template. This component will be attached to your controller through which you are triyng to send the http request. You can pass the merge field to your component and the component can then pass the merge field value to the controller.
For your reference - 

1) This is my VF template -
<messaging:emailTemplate subject="PREBUILD Submission Alert : - {!relatedTo.Opportunity__r.Account.Name}" recipientType="User" relatedToType="Sales_Order__c">
<messaging:htmlEmailBody >
A new Prebuild order has been submitted. The Sales Order details are listed below.<br/><br/><br/> 

Sales Order Name :&nbsp;<apex:outputLink value="https://cs30.salesforce.com/{!relatedTo.Id}">{!relatedTo.Name}<br/></apex:outputLink>
Sales Order Type : {!relatedTo.Type__c}<br/>
Customer Name: {!relatedTo.Opportunity__r.Account.Name} <br/>
Sales Order Owner : {!relatedTo.Owner.Name} <br/>
Nimble AE: {!relatedTo.Opportunity__r.Owner.Name} <br/><br/><br/>

<c:SubmissionTemplateSOcomponent SalesOrderID="{!relatedTo.Id}"/>

<br/><br/>

</messaging:htmlEmailBody>
</messaging:emailTemplate>

2) This is my Component - 
<apex:component controller="SubmissionTemplateSOcomponentController" access="global">
    <apex:attribute name="SalesOrderID" description="To pass ID to controller" type="id" assignTo="{!SOid}"/>
    <!--<apex:outputLabel value="Sales Order Name : "></apex:outputLabel>
        <apex:outputText value="{!SO.Name}"></apex:outputText><br/>
    <apex:outputLabel value="Sales Order Type : "></apex:outputLabel>
        <apex:outputText value="{!SO.Type__c}"></apex:outputText><br/>
    <apex:outputLabel value="Sales Order Owner : "></apex:outputLabel>
        <apex:outputText value="{!SO.Owner.Name}"></apex:outputText><br/><br/><br/>-->
    
    <apex:outputLabel value="Sales Order Lines"></apex:outputLabel><br/>
    
    <table border="1">
    <tr>
    <th>Sales Order Line</th>
    <th>Product</th>
    <th>Quantity</th>
    <th>Sales Price</th>
    <th>Package Product Code</th>
    </tr>
    <apex:repeat value="{!SOlines}" var="sol">
        <tr>
            <td>{!sol.Name}</td>
            <td>{!sol.Product__r.Name}</td>
            <td>{!sol.Quantity__c}</td>
            <td>{!sol.Sale_Price__c}</td>
            <td>{!sol.Package_Product_Code__c}</td>
        </tr>
    </apex:repeat>
    </table>
</apex:component>

3) This is the Controller attached to this component - 
public with sharing class SubmissionTemplateSOcomponentController {
    public ID SOid{get;set;}
    
    public list<Sales_Order_Line__c> getSOlines(){
    list<Sales_Order_Line__c> SOlinesList;
    try{
    SO=[Select s.Type__c, s.Owner.Name, s.Name From Sales_Order__c s where s.Opportunity__c=:oppID and s.Type__c='Prebuild' limit 1];
    SOid=SO.Id;
    }catch(Exception e){}*/
    try{
    SOlinesList=[Select s.Sale_Price__c, s.Quantity__c, s.Product__r.Name, s.Package_Product_Code__c, s.Name, s.BOM_Line_Number__c From Sales_Order_Line__c s where s.Sales_Order__c=:SOid AND (NOT s.BOM_Line_Number__c LIKE '%.%')];
    }catch(Exception e){}
    System.debug('SOlinesList========'+SOlinesList);
    return SOlinesList;
}
}

 
ShashankShashank (Salesforce Developers) 
You may find this helpful: https://developer.salesforce.com/forums/ForumsMain?id=906F000000090IZIAY