You need to sign in to do that
Don't have an account?
David Ovella
how to connect the ID in this apex?
Hello, I'm trying to send emails with information from a custom object called OT__c, but when I receive the email has fields in blank and I think is because I'm not connecting correctly the Id of OT__c in apex to the component to the email template.
my email template
my component
my apex
my email template
<messaging:emailTemplate subject="RE: {!relatedTo.Asunto_email__c}" recipientType="User" relatedToType="OT__c"> <messaging:htmlEmailBody > <br/> <b><u>MAKER S.A</u></b><br/> <b>Nuestra Ref.:</b> <apex:outputText value="{!relatedTo.Name}"/><br/> <br/> <c:Envio_Email_Componente opptyId="{!relatedTo.Id}"/> </messaging:htmlEmailBody> </messaging:emailTemplate>
my component
<apex:component controller="OTPresupuestoControllers" access="global" rendered="true"> <apex:attribute name="opptyId" assignTo="{!otId}" type="String" description="Id OT__c"/> <!--just to see if the variable is working--> {!otId} {!opptyId} <apex:repeat var="ot" value="{!cOTList}"> <div style="font-size:18px;"> <b>Item 1</b> </div> <div style="font-size: 14px;"> <b>Nombre:</b> <apex:outputText value=" {!ot.OT.Nombre_de_la_Cuenta__c}" /> </div> <div style="font-size: 14px;"> <u>Total Gs.:</u> <apex:outputText value=" {!ot.total1} IVA incl."/> </div> <div style="font-size: 14px;"> <b><apex:outputText value="Total a Pagar Gs.: {!ot.totalapagar} IVA incl."/></b> </div> <br/> <div style="font-size: 14px;"> <b>Archivo:</b> <apex:outputText value=" {!ot.OT.Archivo__c}"/> </div> <div style="font-size: 14px;"> <b>Plazo de Entrega:</b> <apex:outputText value=" {!ot.OT.Plazo_de_Entrega__c}hs"/> </div> <div style="font-size: 14px;"> <b>Forma de Pago:</b> <apex:outputText value=" {!ot.OT.Forma_de_Pago__c}"/> </div> <div style="font-size: 14px;"> <b>Requiere Seña:</b> <apex:outputText value=" {!ot.OT.Requiere_Sena__c}" /> </div> </apex:repeat> </apex:component>
my apex
public class OTPresupuestoControllers { public List<cOT> cOTList{get;set;} public String otId {get;set;} //Don't know if this is the correct code public OTPresupuestoControllers() { //OT List this.cOTList = new List<cOT>(); for(OT__c o : [SELECT Id, Total_1__c, Total_a_Pagar__c, Archivo__c, Plazo_de_Entrega__c, Forma_de_Pago__c, Requiere_Sena__c, Nombre_de_la_cuenta__c From OT__c Limit 1]) //it's not working { cOTList.add(new cOT(o)); } } public class cOT{ public OT__c OT{get; set;} public String total1{get;set;} public String totalapagar{get;set;} public cOT(OT__c o){ this.OT = o; this.total1= NumberToSpanishWords.convertToGs(o.Total_1__c); this.totalapagar= NumberToSpanishWords.convertToGs(o.Total_a_Pagar__c); } } }
You know - I had this exact same problem. I'm not sure if this is the correct way to handle it, but I solved it like this.
I created a get and a set method for the ID property. And then I put all the code I needed to get my info in the Setter of the last attribute. I think this is because the getter/setters are called before the constuctor.
So, I think some code like this would fix your issue...
Maybe someone else could confirm why?
All Answers
You know - I had this exact same problem. I'm not sure if this is the correct way to handle it, but I solved it like this.
I created a get and a set method for the ID property. And then I put all the code I needed to get my info in the Setter of the last attribute. I think this is because the getter/setters are called before the constuctor.
So, I think some code like this would fix your issue...
Maybe someone else could confirm why?
thanks Jeffrey