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
Unisoft PhucVVUnisoft PhucVV 

Set a parameter in email template

Hi all,
I created a Email Template by Visualforce.  Then I call a component. Code this:

<apex:component controller="BulkEmailSenderController" access="global">
    <apex:dataTable value="{!selectedOpportunities}" var="s_account">
        <apex:column>
            <apex:facet name="header">Account Name</apex:facet>
            {!s_account.oppObject.Account.Name}}
        </apex:column>
    </apex:dataTable>
</apex:component>

Then I create a send email button. I want set a value in {!selectedOpportunities}. How I can set value in parameter in Salesforce. My function send email:

 Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage(); 
                String[] toAddresses = new String[] {'vopp@systena.co.jp'};
                // Set the paramaters of the email
                email.setTargetObjectId('003N000000Lalmz');
                email.setToAddresses( toAddresses );
                email.setTemplateId('00XN0000000DzEJ');

                // Send the email
                Messaging.SendEmailResult [] r =  Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});  
Best Answer chosen by Unisoft PhucVV
Nitin PaliwalNitin Paliwal
Hi,
You could create a Static property in another Class. Like this

Public class ConstantController{
        public static String constantStringForTemplate{get;set;}
}

and set the property 'constantStringForTemplate' in your function for sendEmail button, whatever you wish.Use this property in your component.

I think it would work.

Thanks
Nitin
 

All Answers

Ashish_Sharma_DEVSFDCAshish_Sharma_DEVSFDC
Hi Unisoft PhucVV,

Use component controller like below to set {!selectedOpportunities} value.
public class BulkEmailSenderController {
	private final List<Opportunity> selectedOpportunities;

	public BulkEmailSenderController() {
		accounts = [select Id,Name from opportunity];
	}

	public List<Opportunity> getSelectedOpportunities() {
		return accounts;
	}
}

Let us know if it helps you.

 
Unisoft PhucVVUnisoft PhucVV
Hi Ashish_Sharma_DEVSFDC,

I want my value will change by code, example: I want set String '123' in this email, but will set String 'abc' for other email. Please help me. Thank all
Ashish_Sharma_DEVSFDCAshish_Sharma_DEVSFDC
Hi,

Can you please explain your requirement in more detail .
Unisoft PhucVVUnisoft PhucVV
User-added image
 
public List<opportunityWrapper> selectedOpportunities {
        get {
            if (selectedOpportunities == null) selectedOpportunities = new List<opportunityWrapper>();
            return selectedOpportunities;
        }
        set;
    }

I created a variable selectedOpportunities contain check object. I want set value of this variable to my email template. How I can do it?
Ashish_Sharma_DEVSFDCAshish_Sharma_DEVSFDC
Hi Unisoft,

Please try below code . Please filter opportunity query as per your need.
public class opportunityWrapper{
	public Opportunity opp{get;set;}
	public boolean isSelected{get;set;}
	public opportunityWrapper(Opportunity opp,boolean isSelected){
		this.opp =opp;
		this.isSelected = isSelected;
	}
}

public List<opportunityWrapper> selectedOpportunities {
        get {
            if (selectedOpportunities == null) selectedOpportunities = new List<opportunityWrapper>();
			for(Opportunity opp:[select id,name from opportunity]){
				selectedOpportunities.add(new opportunityWrapper(opp,false));
			}
            return selectedOpportunities;
        }
        set;
    }

Let us know if it helps you.
Unisoft PhucVVUnisoft PhucVV
I tried but don't success. Example : I have a inputText, when I press send mail Button. I want set value in this inputText to email template. How I can set it?
Nitin PaliwalNitin Paliwal
Hi,
You could create a Static property in another Class. Like this

Public class ConstantController{
        public static String constantStringForTemplate{get;set;}
}

and set the property 'constantStringForTemplate' in your function for sendEmail button, whatever you wish.Use this property in your component.

I think it would work.

Thanks
Nitin
 
This was selected as the best answer