Skip to main content
added 522 characters in body
Source Link
Rory
  • 469
  • 4
  • 18
<messaging:emailTemplate subject="Test to Pass Value" recipientType="Contact" relatedToType="Account">
    <messaging:HTMLEmailBody >
        account: {!relatedTo.Name}
        <c:EmailComp ToID="{!relatedTo.Id}"/>
    </messaging:HTMLEmailBody>
</messaging:emailTemplate>HTMLEmailBody>

</messaging:emailTemplate>

VisualForce Component:

<apex:component controller="EmailController" access="global">
 
    <apex:attribute name="ToID" type="ID" description="the account ID" assignTo="{!accountID}"/>
<h1>{!account.Name}</h1>
    <apex:dataTable value="{!EmailContentAddOns}" var="Add_Ons">var="addOns">
        <apex:column >headerValue="Add On">
        {!addOns}
    <apex</apex:facet name="header">Account Name<column>
</apex:facet>dataTable>

</apex:component>

Apex Controller:

public class EmailController {
     
    public ID accountID{!Add_Ons.Add_ons__cset; get;}

    public Account account {
        </apex:column>get {

    </apex        if (accountId != null && account == null) {
                account = [
                    SELECT Name
                    FROM Account
                    WHERE Id = :dataTable>accountID
<                ];
            }

            /apex:component>/ Always return the account

Apex Controller:

public class EmailController {         return account;
        }

    public List<System__c> AddOns;  set;
    }
    public ID accountID;  
    
    public IDList<System__c> getaccountID()addOns { 
 return accountID; }     get {
    public void setaccountID      if (IDthis.account s){!= null 
        accountID        //&& this.account.Add_Ons__c != s;null
        getEmailContent        && this.addOns == null) {
                this.addOns = new List<System__c>();
    }            
                String accountString = '' + this.account;
    public void generateEmailContent() {         
        AddOns = [select Id, Add_Ons__c    List<System__c> allAddOns = Database.query('Select Add_ons__c From System__csystem__c whereWhere account__caccount__r.Name = :accountID' ];+ accountString);
                
    }            addOns = allAddOns;    
    public List<System__c> getEmailContent() {            
            }

            return AddOns;addOns;
        }

        set;
    }
}
<messaging:emailTemplate subject="Test to Pass Value" recipientType="Contact" relatedToType="Account">
    <messaging:HTMLEmailBody >
        account: {!relatedTo.Name}
        <c:EmailComp />
    </messaging:HTMLEmailBody>
</messaging:emailTemplate>

VisualForce Component:

<apex:component controller="EmailController" access="global">
 
    <apex:attribute name="ToID" type="ID" description="the account ID" assignTo="{!accountID}"/>

    <apex:dataTable value="{!EmailContent}" var="Add_Ons">
        <apex:column >
            <apex:facet name="header">Account Name</apex:facet>
            {!Add_Ons.Add_ons__c}
        </apex:column>
    </apex:dataTable>
</apex:component> 

Apex Controller:

public class EmailController {

    public List<System__c> AddOns;
    
    public ID accountID;
    public ID getaccountID(){ return accountID; }
    public void setaccountID(ID s){
        accountID = s;
        getEmailContent();
    }
    
    public void generateEmailContent() {
        AddOns = [select Id, Add_Ons__c From System__c where account__c = :accountID ];
        
    }
    public List<System__c> getEmailContent() {
        return AddOns;
    
    }
}
<messaging:emailTemplate subject="Test to Pass Value" recipientType="Contact" relatedToType="Account">
<messaging:HTMLEmailBody >
    account: {!relatedTo.Name}
    <c:EmailComp ToID="{!relatedTo.Id}"/> 
</messaging:HTMLEmailBody>

</messaging:emailTemplate>

VisualForce Component:

<apex:component controller="EmailController" access="global">
<apex:attribute name="ToID" type="ID" description="the account ID" assignTo="{!accountID}"/>
<h1>{!account.Name}</h1>
<apex:dataTable value="{!AddOns}" var="addOns">
    <apex:column headerValue="Add On">
        {!addOns}
    </apex:column>
</apex:dataTable>

</apex:component>

Apex Controller:

public class EmailController {
     
    public ID accountID{set; get;}

    public Account account {
        get {

            if (accountId != null && account == null) {
                account = [
                    SELECT Name
                    FROM Account
                    WHERE Id = :accountID
                ];
            }

            // Always return the account
            return account;
        }

        set;
    }
        
    
    public List<System__c> addOns { 
        get {
            if (this.account != null 
                //&& this.account.Add_Ons__c != null
                && this.addOns == null) {
                this.addOns = new List<System__c>();
                
                String accountString = '' + this.account;
                
                List<System__c> allAddOns = Database.query('Select Add_ons__c From system__c Where account__r.Name = ' + accountString);
                
                addOns = allAddOns;    
                   
            }

            return addOns;
        }

        set;
    }
}
added 499 characters in body
Source Link
Rory
  • 469
  • 4
  • 18

My end goal of this project is to have a salesperson use a template to auto-generate an email to a contact. This email template will look through all the systems for a particular account, figure out which add-ons they don't have, and populate the email with verbiage for those add-ons. I don't know if this is possible, but it would be great to use this email template in Gmail (using Cirrus Insight) and have an entry field pop up where the user can enter the account name. Cirrus allows users to enter specific info into merge fields for things like {!Contact} or {!Opportunity} but I don't know how this would work for a "variable" being passed into a customer controller. It is not a merge field so I don't think Cirrus can handle this. Is there a way to create a pop-up window?

My end goal of this project is to have a salesperson use a template to auto-generate an email to a contact. This email template will look through all the systems for a particular account, figure out which add-ons they don't have, and populate the email with verbiage for those add-ons.

My end goal of this project is to have a salesperson use a template to auto-generate an email to a contact. This email template will look through all the systems for a particular account, figure out which add-ons they don't have, and populate the email with verbiage for those add-ons. I don't know if this is possible, but it would be great to use this email template in Gmail (using Cirrus Insight) and have an entry field pop up where the user can enter the account name. Cirrus allows users to enter specific info into merge fields for things like {!Contact} or {!Opportunity} but I don't know how this would work for a "variable" being passed into a customer controller. It is not a merge field so I don't think Cirrus can handle this. Is there a way to create a pop-up window?

Tweeted twitter.com/StackSalesforce/status/949034390067339264
Source Link
Rory
  • 469
  • 4
  • 18

Passing user entered values from Visualforce template to Apex Controller

A little background. We created a new object for our product called 'Systems'. This 'Systems" object has a multi picklist field for 'Add-Ons' depending on what the customer has loaded on their system. Each 'System' is tied to an account and an account can have multiple systems.

My end goal of this project is to have a salesperson use a template to auto-generate an email to a contact. This email template will look through all the systems for a particular account, figure out which add-ons they don't have, and populate the email with verbiage for those add-ons.

I quickly found out that creating this email template was going to be more complicated than just using Salesforce Merge fields. I need the ability to add or remove entire paragraphs depending on an account's data. I did some research and found that this could possibly be done using Visualforce Templates, Components, and Apex Controllers.

I was able to use a controller, component, and template to pull add-on data from an account using the API call with an account name hardcoded in. I need the ability for a user to enter in which account they are emailing about, however.

I threw together some code that doesn't look quite right but I feel I am stuck. I am starting small with basics and only trying to display all the add-ons a particular account has in the email for now. Can anyone help me out here? Is there a way easier way to do this that I am missing?

VisualForce Template:

<messaging:emailTemplate subject="Test to Pass Value" recipientType="Contact" relatedToType="Account">
    <messaging:HTMLEmailBody >
        account: {!relatedTo.Name}
        <c:EmailComp />
    </messaging:HTMLEmailBody>
</messaging:emailTemplate>

VisualForce Component:

<apex:component controller="EmailController" access="global">

    <apex:attribute name="ToID" type="ID" description="the account ID" assignTo="{!accountID}"/>

    <apex:dataTable value="{!EmailContent}" var="Add_Ons">
        <apex:column >
            <apex:facet name="header">Account Name</apex:facet>
            {!Add_Ons.Add_ons__c}
        </apex:column>
    </apex:dataTable>
</apex:component> 

Apex Controller:

public class EmailController {

    public List<System__c> AddOns;
    
    public ID accountID;
    public ID getaccountID(){ return accountID; }
    public void setaccountID(ID s){
        accountID = s;
        getEmailContent();
    }
    
    public void generateEmailContent() {
        AddOns = [select Id, Add_Ons__c From System__c where account__c = :accountID ];
        
    }
    public List<System__c> getEmailContent() {
        return AddOns;
    
    }
}