0

I have a web form contains few fields such as: first and last name, email, phone, three checkboxes, and a submit button.

When the user fills out the form, and hits submit, an automatic email is been sent to the designated recipient.

My question is how can we populate the checkbox selected value in the email? The email content is something like this:

A new donor would like to share an in-kind gift!

[FIRST NAME][LAST NAME]

Here is a link to their record:

[IN-KIND DONATION TYPE](Check box field on the form)

[DESCRIPTION]

I appreciate your help with this!

From,
ABC.

2
  • 2
    how you are sending emails after submission? Mar 21, 2017 at 20:18
  • from outbound email in apex class like SingleEmailMessage mail = new Messaging.SingleEmailMessage(); Messaging
    – SFDC
    Mar 22, 2017 at 0:24

1 Answer 1

0

I can see this being done one of two ways:

  1. Adding the value of the field directly to the body of the email
  2. Adding the field to an email template and applying that template to your message. Note this only works if your form inserts a record. if it does not insert a record you'll have to use option 1. Option 1 works whether or not a record is inserted.

Step 1 is making sure your variable is bound to the controller:

<apex:inputCheckbox value={!controllerVariable} />

OR

<apex:inputField value={!tempRecord.fieldName__c} />

Once you have it bound to the controller you can add it into your email:

public boolean controllerVariable {get;set;} // Method 1

// Method 2
public Object tempRecord {
    get {
        return tempRecord != null ? tempRecord : new Object();
    }

    set;
}


public void sendEmail() {
    Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();

    // Method 1:
    message.textBody = 'message text ' + controllerVariable + ' More message text';

    // Method 2
    insert tempRecord;
    message.setTargetObjectId(tempREcord.Id);
}

With Method 2, you have to set up the email template as well: Docs

2
  • Toby Thanks for the reply.I have a question I am using Email template to send an email my question is how can I get the web form variable on the email template? or we do not know what user going to select which check box out of three so that selected checkbox value need to be populated on the email as i should in the above message.Three check boxes are 1.Clothes Donation 2.Food Donation 3.Others Donation.
    – SFDC
    Mar 21, 2017 at 22:21
  • Since it's a template the ONLY way to do it is to use method 2 I describe above. Create a custom object to store the data from your form. When users hit submit on your form, insert that record into the database. Then, use method 2 above to assign the record to the email template.
    – gNerb
    Mar 21, 2017 at 23:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .