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
David OvellaDavid Ovella 

My email template is sending information with some fields in blank

I created a visual email template that works with:
--a custom object called OT__c,
--a visualforce component called OTComponente, and
--an apex class called OTPresupuesto.

My problem is when I receive the email, it has some fields in blank, I think it has to do with the id of the custom object.
Specifically this part:
From OT__c Where Id=:System.currentPagereference().getParameters().get('Id')
when I put in my apex class just the "From OT__c" without specifying my Id, the email I recieve looks like this:
 
Nuestra Ref.:
Sucursal:
Fecha:24/08/2015

Total a Pagar:0,00
Saldo a Pagar:0,00 
Sub Total:0,00
Nombre:
RUC:
Name:

Gracias por elegir Maker!
Saludos Cordiales,
El equipo de Makerxmail


and when I put the "From OT__c Where Id=:System.currentPagereference().getParameters().get('Id')" the email looks like this (​the component doesn't even appear):
Nuestra Ref.:
Sucursal:
Fecha:24/08/2015 


Gracias por elegir Maker!
Saludos Cordiales,
El equipo de Makerxmail






this is my apex class OTPresupuesto
public with sharing class OTPresupuesto {

    public List<fact> factList{get;set;}
      
    //Constructor  
    public OTPresupuesto() {
        this.factList = new List<fact>();
        for(OT__c ot2 :[Select Name, Nombre_de_la_Cuenta__c, Sub_Total__c, RUC__c,
                        Total_a_Pagar__c,Saldo_a_Pagar__c
                        From OT__c Where Id=:System.currentPagereference().getParameters().get('Id')  LIMIT 1])
        {
            factList.add(new fact(ot2));
        }
        
    }       
    
    public class fact{                   
        public OT__c OT{get; set;}                  
        public string saldoPagar {get; set;}
        public string subTotal {get; set;}
        public string totalPagar {get; set;}
                   
        public fact(OT__c ot2){                           
            this.OT = ot2;                           
            this.saldoPagar= NumberToSpanishWords.convertToEU(ot2.Saldo_a_Pagar__c);  
            this.subTotal= NumberToSpanishWords.convertToEU(ot2.Sub_Total__c);
            this.totalPagar= NumberToSpanishWords.convertToEU(ot2.Total_a_Pagar__c);
        }   
    }     
}



and my visual component OTComponente
<apex:component controller="OTPresupuesto" access="global">
        
        <apex:repeat var="as" value="{!factList}">               
                Total a Pagar: <apex:outputText value="{!as.totalPagar}"/><br/>
                Saldo a Pagar: <apex:outputText value="{!as.saldoPagar}"/> <br/> 
                Sub Total: <apex:outputText value="{!as.subTotal}"/><br/> 
                Nombre: <apex:outputText value="{!as.OT.Nombre_de_la_Cuenta__c}"/><br/>
                RUC: <apex:outputText value="{!as.OT.RUC__c}"/>  <br/>
                Name: <apex:outputText value="{!as.OT.Name}"/>   <br/>   
        </apex:repeat>    
</apex:component>


this is my visual email template called EnvioPresupTemaplate
<messaging:emailTemplate subject="RE: {!relatedTo.Asunto_email__c}" recipientType="User" relatedToType="OT__c">
<messaging:htmlEmailBody >       
    <br/>
    <b>Nuestra Ref.:</b><apex:outputText value="{!relatedTo.Name}"/><br/>
    
    Sucursal:<apex:outputField value="{!relatedTo.Sucursal__c}"/><br/> 
    Fecha:<apex:outputField value="{!relatedTo.Fecha__c}"/><br/>
    
    <br/><c:OTComponente />
    <br/>
    <br/>
    Gracias por elegir Maker!<br/>
    Saludos Cordiales,<br/>
    El equipo de Makerxmail
</messaging:htmlEmailBody>
</messaging:emailTemplate>





 
Best Answer chosen by David Ovella
Vishal_GuptaVishal_Gupta
Hi David,

Please do the below changes in your code:

In Apex Class OTPresupuesto
public with sharing class OTPresupuesto {
	
    public Id otpId { get; set; }
    public List<fact> factList
    {
        get
        {
			for(OT__c ot2 :[Select Name, Nombre_de_la_Cuenta__c, Sub_Total__c, RUC__c,
                        Total_a_Pagar__c,Saldo_a_Pagar__c
                        From OT__c Where Id=:otpId  LIMIT 1])
			{
				factList.add(new fact(ot2));
			}
           	return factList;
        }
        set;
    }
     
    //Constructor  
    public OTPresupuesto() {
        
    }       
    
    public class fact{                   
        public OT__c OT{get; set;}                  
        public string saldoPagar {get; set;}
        public string subTotal {get; set;}
        public string totalPagar {get; set;}
                   
        public fact(OT__c ot2){                           
            this.OT = ot2;                           
            this.saldoPagar= NumberToSpanishWords.convertToEU(ot2.Saldo_a_Pagar__c);  
            this.subTotal= NumberToSpanishWords.convertToEU(ot2.Sub_Total__c);
            this.totalPagar= NumberToSpanishWords.convertToEU(ot2.Total_a_Pagar__c);
        }   
    }     
}

In Component OTComponente :
<apex:component controller="OTPresupuesto" access="global">
        <apex:attribute name="vOTPId" type="Id" assignTo="{!otpId}" description="Id of OPT" />
        <apex:repeat var="as" value="{!factList}">               
                Total a Pagar: <apex:outputText value="{!as.totalPagar}"/><br/>
                Saldo a Pagar: <apex:outputText value="{!as.saldoPagar}"/> <br/> 
                Sub Total: <apex:outputText value="{!as.subTotal}"/><br/> 
                Nombre: <apex:outputText value="{!as.OT.Nombre_de_la_Cuenta__c}"/><br/>
                RUC: <apex:outputText value="{!as.OT.RUC__c}"/>  <br/>
                Name: <apex:outputText value="{!as.OT.Name}"/>   <br/>   
        </apex:repeat>    
</apex:component>

In VF EMail Template EnvioPresupTemaplate
<messaging:emailTemplate subject="RE: {!relatedTo.Asunto_email__c}" recipientType="User" relatedToType="OT__c">
<messaging:htmlEmailBody >       
    <br/>
    <b>Nuestra Ref.:</b><apex:outputText value="{!relatedTo.Name}"/><br/>
    
    Sucursal:<apex:outputField value="{!relatedTo.Sucursal__c}"/><br/> 
    Fecha:<apex:outputField value="{!relatedTo.Fecha__c}"/><br/>
    
    <br/><c:OTComponente  vOTPId="{!relatedTo.Id}" />
    <br/>
    <br/>
    Gracias por elegir Maker!<br/>
    Saludos Cordiales,<br/>
    El equipo de Makerxmail
</messaging:htmlEmailBody>
</messaging:emailTemplate>
Please let me know if you need more help.

Thanks,
Vishal

All Answers

Vishal_GuptaVishal_Gupta
Hi David,

Please do the below changes in your code:

In Apex Class OTPresupuesto
public with sharing class OTPresupuesto {
	
    public Id otpId { get; set; }
    public List<fact> factList
    {
        get
        {
			for(OT__c ot2 :[Select Name, Nombre_de_la_Cuenta__c, Sub_Total__c, RUC__c,
                        Total_a_Pagar__c,Saldo_a_Pagar__c
                        From OT__c Where Id=:otpId  LIMIT 1])
			{
				factList.add(new fact(ot2));
			}
           	return factList;
        }
        set;
    }
     
    //Constructor  
    public OTPresupuesto() {
        
    }       
    
    public class fact{                   
        public OT__c OT{get; set;}                  
        public string saldoPagar {get; set;}
        public string subTotal {get; set;}
        public string totalPagar {get; set;}
                   
        public fact(OT__c ot2){                           
            this.OT = ot2;                           
            this.saldoPagar= NumberToSpanishWords.convertToEU(ot2.Saldo_a_Pagar__c);  
            this.subTotal= NumberToSpanishWords.convertToEU(ot2.Sub_Total__c);
            this.totalPagar= NumberToSpanishWords.convertToEU(ot2.Total_a_Pagar__c);
        }   
    }     
}

In Component OTComponente :
<apex:component controller="OTPresupuesto" access="global">
        <apex:attribute name="vOTPId" type="Id" assignTo="{!otpId}" description="Id of OPT" />
        <apex:repeat var="as" value="{!factList}">               
                Total a Pagar: <apex:outputText value="{!as.totalPagar}"/><br/>
                Saldo a Pagar: <apex:outputText value="{!as.saldoPagar}"/> <br/> 
                Sub Total: <apex:outputText value="{!as.subTotal}"/><br/> 
                Nombre: <apex:outputText value="{!as.OT.Nombre_de_la_Cuenta__c}"/><br/>
                RUC: <apex:outputText value="{!as.OT.RUC__c}"/>  <br/>
                Name: <apex:outputText value="{!as.OT.Name}"/>   <br/>   
        </apex:repeat>    
</apex:component>

In VF EMail Template EnvioPresupTemaplate
<messaging:emailTemplate subject="RE: {!relatedTo.Asunto_email__c}" recipientType="User" relatedToType="OT__c">
<messaging:htmlEmailBody >       
    <br/>
    <b>Nuestra Ref.:</b><apex:outputText value="{!relatedTo.Name}"/><br/>
    
    Sucursal:<apex:outputField value="{!relatedTo.Sucursal__c}"/><br/> 
    Fecha:<apex:outputField value="{!relatedTo.Fecha__c}"/><br/>
    
    <br/><c:OTComponente  vOTPId="{!relatedTo.Id}" />
    <br/>
    <br/>
    Gracias por elegir Maker!<br/>
    Saludos Cordiales,<br/>
    El equipo de Makerxmail
</messaging:htmlEmailBody>
</messaging:emailTemplate>
Please let me know if you need more help.

Thanks,
Vishal
This was selected as the best answer
David OvellaDavid Ovella
thanks for answer Vishal,

I replaced my code with yours, and it looks ok until I try to send an email, it appears one error
User-added image
i'm trying to understand but doesn't give any details about what it may be wrong just the "Attempt to de reference a null object"
 
Vishal_GuptaVishal_Gupta
Hi David,

I have tried in my personal org and its working fine, not sure why it is not working for you, if possible can you share your org with me for half an hour. My email id is vishal.er.gupta@gmail.com or we can discuss on Skype at vishal.gupta293 

Thanks,
Vishal