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
watanabe2watanabe2 

Visualforce Email Template: parameter for query

I have a Visualforce template designed to pull a list of leads belonging to the recipient of the email. I'm using a component inside of the VF template to display the leads.

 

It seems the user Id is being lost somewhere in the transition from the VF page to the controller. Consequently I'm getting no records back for display by the component.

 

Email template:

<messaging:emailTemplate subject="Reminder: Inactive Opportunity Reminder for: {!Relatedto.Name}" recipientType="User"
relatedToType="User">
    
    <messaging:htmlEmailBody >
        <p>The following leads have not yet been updated:</p>
        <c:Digilant_InactiveLeads ToID="{!RelatedTo.ID}" />
        
        <p>To update these leads, click on the "Lead Status" field located in the upper right on the lead page layout.</p>
    </messaging:htmlEmailBody>
</messaging:emailTemplate>

 Component:

<apex:component controller="Digilant_findInactiveLeads" access="global">
    <apex:attribute name="ToID" type="ID" description="the lead owner ID" assignTo="{!salesRepID}"/>
    
    <apex:dataTable value="{!InactiveLeads}" var="i_lead">
        <apex:column >
            <apex:facet name="header">Name</apex:facet>
            {!i_lead.Name}
        </apex:column>
        
        <apex:column >
            <apex:facet name="header">Source</apex:facet>
            {!i_lead.LeadSource}
        </apex:column>
        
         <apex:column >
            <apex:facet name="header">Created Date</apex:facet>
            {!i_lead.CreatedDate}
        </apex:column>
    </apex:dataTable>

</apex:component>

 Controller:

public class Digilant_findInactiveLeads {
    public List<Lead> leads {get; set;}
    public ID salesRepID {get; set;}

    public Digilant_findInactiveLeads() {
       leads = [select Name, LeadSource, CreatedDate from Lead from Lead where status = 'Open' AND ownerId =: salesRepID];
    }

    public List<Lead> getInactiveLeads() {
        return leads;
    }
}

 

Best Answer chosen by Admin (Salesforce Developers) 
Kamatchi Devi SargunanathanKamatchi Devi Sargunanathan

Hi,

 

I have slightly changed your codes. Try the following Component and controller.

 

Component:

<apex:component controller="Digilant_findInactiveLeads" access="global">
    <apex:attribute name="ToID" type="ID" description="the lead owner ID" assignTo="{!salesRepID}"/>
     
        <apex:datatable value="{!InactiveLeads}" var="item" border="1">
                    <apex:column headervalue=" Name ">
                        <apex:outputText value="{!item.name}"/>
                    </apex:column>
                     <apex:column headervalue=" Source ">
                        <apex:outputText value="{!item.LeadSource}"/>
                    </apex:column>
                     <apex:column headervalue=" Created Date ">
                        <apex:outputText value="{!item.CreatedDate}"/>
                    </apex:column>
       </apex:datatable>
</apex:component>

Controller:

public class Digilant_findInactiveLeads {   
  //capture the user id
    public ID salesRepID {get; set;}
    public List<Lead> InactiveLeads = new List<Lead>();

    public List<Lead> getInactiveLeads() {
        InactiveLeads = [select Name, LeadSource, CreatedDate from Lead from Lead where status = 'Open' AND ownerId =: salesRepID];
        return InactiveLeads;
    }
}

 

The mistake you have done is returned another lead list from controller in InactiveList that has not been initialized.

 

Hope so this helps you...!

Please mark this answer a Solution and please give kudos by clicking on the star icon, if you found this answer as helpful.

 

All Answers

Kamatchi Devi SargunanathanKamatchi Devi Sargunanathan

Hi,

 

I have slightly changed your codes. Try the following Component and controller.

 

Component:

<apex:component controller="Digilant_findInactiveLeads" access="global">
    <apex:attribute name="ToID" type="ID" description="the lead owner ID" assignTo="{!salesRepID}"/>
     
        <apex:datatable value="{!InactiveLeads}" var="item" border="1">
                    <apex:column headervalue=" Name ">
                        <apex:outputText value="{!item.name}"/>
                    </apex:column>
                     <apex:column headervalue=" Source ">
                        <apex:outputText value="{!item.LeadSource}"/>
                    </apex:column>
                     <apex:column headervalue=" Created Date ">
                        <apex:outputText value="{!item.CreatedDate}"/>
                    </apex:column>
       </apex:datatable>
</apex:component>

Controller:

public class Digilant_findInactiveLeads {   
  //capture the user id
    public ID salesRepID {get; set;}
    public List<Lead> InactiveLeads = new List<Lead>();

    public List<Lead> getInactiveLeads() {
        InactiveLeads = [select Name, LeadSource, CreatedDate from Lead from Lead where status = 'Open' AND ownerId =: salesRepID];
        return InactiveLeads;
    }
}

 

The mistake you have done is returned another lead list from controller in InactiveList that has not been initialized.

 

Hope so this helps you...!

Please mark this answer a Solution and please give kudos by clicking on the star icon, if you found this answer as helpful.

 

This was selected as the best answer
Mohith Kumar ShrivastavaMohith Kumar Shrivastava

http://salesforce.stackexchange.com/questions/18642/parameter-not-being-passed-in-visualforce-template

 

Cross linking the analysis i did on stack as question was there too.I would say its order of execution rather than intialiization.The code wont run if query is in constructor 

Michael MMichael M
HI Kamatchi/Mohith,

This is excellent. I am using your above recommendation. I need this to send out once a month. How exactly would I do that? Of course I only want to send it to users who own at least 1 lead record!!