8

I've tried to schedule a recurring email but it seems the "salesRepID" parameter is not receiving the value from the "ToID" assignment because the proper records aren't being retrieved in the query at the controller level. The query works without the "salesRepID" parameter.

my VF 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>

my 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;
   }
 }

my 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>

If anyone wants to give pointers on how to watch variables I'd appreciate that as well. I'm trying to RTFM now.

1 Answer 1

7

Step By Step analysis of the problem

1)Analysed to check whether data is populating in {!RelatedTo.Id}.

Here is the email template code modified

<messaging:emailTemplate subject="hello" recipientType="User" relatedToType="User">

 <messaging:htmlEmailBody >
    {!RelatedTo.Id}//Debug log for me at first stage .Thankfully Id there populated
  <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>

2)Next lets analyse whether the value is passed to setter through attribute and assigned in controller and got back in page from controller

<apex:component controller="Digilant_findInactiveLeads" access="global">
   <apex:attribute name="ToID" type="string" description="the lead owner ID" assignTo="{!salesRepID}"/>

  <apex:outputText value="{!salesRepID}"></apex:outputText><!--observe the debug here and found got this populated .meaning setters are really getting set properly-->

  {!InactiveLeads}<!--log the result coming from list ...Found thats the root cause no data is returned and list is blank-->

<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>

3)Analyzing the 2nd step revealed me that the setter is set and the getter is also returning but the query did not return any result or the return object did not get set to yield the desired result

4)Solution was to remove the query from constructor and insert in getter only to see if that helps

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

  public Digilant_findInactiveLeads() {

 }

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

5)Final conclusion ,Here there is no action methods and hence as per order of execution constructors run first and the variable salesRepID was not set when query ran .Hence i moved it in getter to resolve this .

5
  • Ah, order of execution error. I see. I also posted on the salesforce success community site. The answer I received there was essentially the same, but with the small difference that instead of salesRepID being a property they switched that to a list and allocated it with new. I haven't tested it with a property - not sure if this is ok. Commented Oct 23, 2013 at 19:23
  • 2
    Excellent analysis though. Thank you! Commented Oct 23, 2013 at 19:26
  • Please upvote and if it works mark it ticked!Thanks Commented Oct 23, 2013 at 19:27
  • Found the answer you got on boards Commented Oct 23, 2013 at 19:40
  • boards.developerforce.com/t5/Visualforce-Development/… what i see is since again the query is in getter not in constructor and moved out it works .But again my conclusion is clear its due to order of execution as the root cause Commented Oct 23, 2013 at 19:41

You must log in to answer this question.

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