You need to sign in to do that
Don't have an account?

Problem with visual force component
HI. I have a requirement to send email with some data in the email. For this I have written the following:
1. Apex class
2. Visual Force page.
3. VisualForce Component.
4. Email Template
5. Button in the object.
It should work something like this: When the button, called as Order Status, is clicked the controller should query the data from the database and it should be displayed in the VisualForce page. This is working fine.
In the VisualForce page I have created 2 buttons, namely, Send Email and Cancel. On click of the "Send Email" button an email should be sent. This is also working fine but the email being sent is going without any data i.e. the queried is not being populated. In the VisualForce Page it is working fine but not in the VisualForce Component.
Please help. I am trying this since 5-6days and still no change.
Hi,
Maybe share it here how you send the email?
Thanks.
Regards,
Hengky
Maybe try to add debug in your apex class (that get the data to the component), and see in the debug log if in the code you get the data
Error is in VisualForce Component: Error Msg is: Unknown property 'OrderStatus.POWrapperClass.PO_No__c'
APEX CLASS:
global class OrderStatus{
Id accId;
global String name {get;set;}
global List<Sales_Order__c> pendingorder { get;set;}
global List<Sales_Order__c> recentDespatch { get; set;}
global List<Sales_Order__c> pending { get; set; }
global List<Sales_Order__c> despatch { get; set; }
global List pending1 { get; set; }
global List despatch1 { get; set; }
private final Account account;
public OrderStatus(){
try{
account = [select Name,id, (SELECT Contact.Name, Contact.Email FROM Account.Contacts where Contact.Email != null AND Credit_Report__c LIKE 'Yes' ) from Account where id = :ApexPages.currentPage().getParameters().get('id')]; system.debug('try block:'+account);
} catch(Exception e){
System.debug('error sending mail'+e);
}
}
// Code block for "Send Mail" button
public pagereference sendemai(){
String addresses;
String accId = Apexpages.currentPage().getParameters().get('id');
System.debug('Control Enters Send Email Button Code Block');
Messaging.SingleEmailMessage email1 = new Messaging.SingleEmailMessage();
EmailTemplate template = [select id from EmailTemplate where name ='Order_Status_Email'];
system.debug('Control selects the Email Template:'+template);
if(account != null)
accId = account.id ;
Contact c = new Contact( AccountId = accId,LastName = 'Testabc',Email='abhijeet.purohit01@gmail.com',CurrencyIsoCode = 'INR',MobilePhone = '9886098860',Credit_Report__c = 'NO');
insert c; System.debug('contact id = ' + c.id); System.debug('Contact Email ID is selected'); try{ System.debug('Email will be sent now');
email1.setSenderDisplayName('The Production Team');
email1.setTemplateId(template.id);
email1.setTargetObjectId(c.id);
Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email1});
delete c;
System.debug('Control Exits Send Email Button Code Block');
} catch(Exception e){
System.debug('Error while sending Mail :'+e.getMessage());
delete c;
}
System.debug('Send Email Code Block Ends Here.');
return new PageReference('/'+accId);
}
// End of Code Block for "Send Email" button.
// Code block for "Cancel" Button
public pagereference cancelemai(){
system.debug('Control enters Cancel Button Code Block.');
system.debug('Exits Cancel Button');
return new PageReference('/'+accId); }
//Querying data for visualforce page from Invoice object.
public pageReference querySalesOrder(){
System.debug('Control Enters Visual Force Page Code Block');
pendingorder = new List<Sales_Order__c>();
recentDespatch = new List<Sales_Order__c>();
pending = new List<Sales_Order__c>();
despatch = new List<Sales_Order__c>();
accId = Apexpages.currentPage().getParameters().get('id');
system.debug('account ID:'+accID);
// Don't delete these 3 lines
Account acnt = new Account();
acnt = [ select Name from Account where Id =: accId ];
name = acnt.name ;
pendingOrder = [ select PO_No__c, Balance_Quantity__c, Product_Description__c, Sales_Order_Status__c, Current_Despatch_Date_2__c from Sales_Order__c WHERE Account_Name__c =: accId AND (Sales_Order_Status__c != 'Closed') ORDER BY Current_Despatch_Date_2__c ];
System.debug('Queried from pendingorders:'+pendingorder);
for(Sales_Order__c s : pendingOrder){
pending.add(s); system.debug('Pending:'+pending);
}
recentDespatch = [select PO_No__c, Invoice__r.Name, Quote_Quantity__c, Invoiced_Quantity__c, PO_Quantity__c, Product_Description__c, Tentative_Despatch_Date__c, Sales_Order_Status__c FROM Sales_Order__c WHERE Account_Name__c =: accId AND Actual_Despatch_Date_Time__c != Null AND (Sales_Order_Status__c LIKE 'Closed') ORDER BY Tentative_Despatch_Date__c asc limit 10 ]; System.debug('RecentDespatches:'+recentDespatch);
for(Sales_Order__c s1 : recentDespatch){
despatch.add(s1);
System.debug('Despatch:'+despatch); }
return null;
}
// querying data for component
public pageReference querySO(){
System.debug('Control enters VisualForce Component code block');
pendingOrder = new List<Sales_Order__c>();
recentDespatch = new List<Sales_Order__c>();
pending1 = new List();
despatch1 = new List();
accId = ApexPages.currentPage().getParameters().get('id');
System.debug('Account ID'+accId);
Account acc1 = new Account();
acc1 = [SELECT Name FROM Account WHERE id=: accId];
name = acc1.Name;
pendingOrder = [ select PO_No__c, Balance_Quantity__c, Product_Description__c, Sales_Order_Status__c, Current_Despatch_Date_2__c from Sales_Order__c WHERE Account_Name__c =: accId AND (Sales_Order_Status__c != 'Closed') ORDER BY Current_Despatch_Date_2__c ];
System.debug('Queried from Pending Order visual component:'+pendingorder);
for( Sales_Order__c so1 : pendingOrder ){
pending1.add( new POWrapperClass(so1.PO_No__c, so1.Balance_Quantity__c, so1.Product_Description__c, so1.Sales_Order_Status__c, so1.Current_Despatch_Date_2__c));
// pending1.add(so1);
system.debug('Wrapper Pending1:'+pending1);
}
recentDespatch = [select PO_No__c, Invoice__r.Name, Quote_Quantity__c, Invoiced_Quantity__c, PO_Quantity__c, Product_Description__c, Tentative_Despatch_Date__c, Sales_Order_Status__c FROM Sales_Order__c WHERE Account_Name__c =: accId AND Actual_Despatch_Date_Time__c != Null AND (Sales_Order_Status__c LIKE 'Closed') ORDER BY Tentative_Despatch_Date__c asc limit 10 ]; System.debug('Queried from Recent Despatch visual force component:'+recentDespatch);
for( Sales_Order__c so2 : recentDespatch ){
despatch1.add(new RDWrapperClass(so2.PO_No__c, so2.Invoice__r.Name, so2.Invoiced_Quantity__c, so2.Product_Description__c, so2.Tentative_Despatch_Date__c));
// despatch1.add(so2);
system.debug('Wrapper Despatch1:'+despatch1);
}
return null;
}
// Wrapper class for pending orders
public class POWrapperClass{
String poNo;
Decimal balQty;
String pDesc;
String status;
DateTime cDespatch;
public POWrapperClass(String poNo, Decimal balQty, String pDesc, String status, DateTime cDespatch){
this.poNo = poNo;
this.balQty = balQty;
this.pDesc = pDesc;
this.status = status;
this.cDespatch = cDespatch;
}
}
// Wrapper class for recent despatches.
public class RDWrapperClass{
String poNo;
String invName;
Decimal qQty;
Decimal invQty;
Decimal poQty;
String pDesc;
DateTime tDespatch;
String status;
public RDWrapperClass( String poNo, String invName, Decimal invQty, String pDesc, DateTime tDespatch){
this.poNo = poNo;
this.invName = invName;
this.invQty = invQty;
this.pDesc = pDesc;
this.tDespatch = tDespatch;
} } }
Error is in VisualForce Component: Error Msg is: Unknown property 'OrderStatus.POWrapperClass.PO_No__c'
VISUAL FORCE PAGE:
<apex:page controller="OrderStatus" showheader="false" action="{!querySalesOrder}">
<head>
<title>Order Status </title>
</head>
<apex:form >
<apex:pageblock tabstyle="Account">
<apex:pageBlockButtons >
<apex:commandButton value="Send Mail" action="{!SendEmai}" />
<apex:commandButton value="Cancel" action="{!CancelEmai}" />
</apex:pageBlockButtons>
<!--
*************************************************************************************************************************
-->
<div style="width:100%;background-color:#D1E1FF; height: 25px;">
<table style="width:100%;background-color:#D1E1FF">
<tr>
<td colSpan="2">
<b><font face="arial" size="2" color="Black">▼ Pending Orders</font></b>
</td>
</tr>
</table>
</div>
<br/>
<table border="0" columns="1" width="100%" style="position: relative; top: -2px;border:solid #767676;background-color:#767676">
<tr style="border:#000000;">
<td width="15%" align="left"><FONT COLOR="#FFFFFF"><b>PO Number</b></FONT></td>
<td width="16%" align="center"><FONT COLOR="#FFFFFF"><b>Balance Quantity</b></FONT></td>
<td width="20%" align="center"><FONT COLOR="#FFFFFF"><b>Product Name</b></FONT></td>
<td width="20%" align="center"><FONT COLOR="#FFFFFF"><b>Status</b></FONT></td>
<td width="29%" align="right"><FONT COLOR="#FFFFFF"><b>Planned Despatch Date/Time</b></FONT></td>
</tr>
</table>
<table BGCOLOR="#FFFFFF" columns="1" width="100%" RULES="rows">
<apex:repeat value="{!pending}" var="so" >
<tr>
<td width="15%" align="left" style=" windowtext 1.0pt; font-family: Arial; font-size: 10pt">
<apex:outputText value="{!so.PO_No__c}"/>
</td>
<td width="16%" align="center" style=" windowtext 1.0pt; font-family: Arial; font-size: 10pt">
<apex:outputText value="{!so.Balance_Quantity__c}"/>
</td>
<td width="20%" align="center" style=" windowtext 1.0pt; font-family: Arial; font-size: 10pt">
<apex:outputText value="{!so.Product_Description__c}" />
</td>
<td width="20%" align="center" style=" windowtext 1.0pt; font-family: Arial; font-size: 10pt">
<apex:outputText value="{!so.Sales_Order_Status__c}" />
</td>
<td width="29%" align="right" style=" windowtext 1.0pt; font-family: Arial; font-size: 10pt" >
<apex:outputText value="{0,date,dd'/'MM'/'yyyy}">
<apex:param value="{!so.Current_Despatch_Date_2__c}" />
</apex:outputText>
</td>
</tr>
</apex:repeat>
</table>
<br/>
<br/>
<div style="width:100%;background-color:#D1E1FF; height: 25px;">
<table style="width:100%;background-color:#D1E1FF">
<tr>
<td colSpan="2">
<b><font face="arial" size="2" color="Black">▼ Recent Despatches</font></b>
</td>
</tr>
</table>
</div>
<br/>
<table border="0" columns="4" width="100%" style="position: relative; top: -2px;border:solid #767676;background-color:#767676">
<tr style="border:#000000;">
<td width="15%" align="left"><FONT COLOR="#FFFFFF"><b>PO Number</b></FONT></td>
<td width="25%" align="center"><FONT COLOR="#FFFFFF"><b>Invoice Number</b></FONT></td>
<td width="15%" align="center"><FONT COLOR="#FFFFFF"><b>Quantity</b></FONT></td>
<td width="20%" align="center"><FONT COLOR="#FFFFFF"><b>Product Name</b></FONT></td>
<td width="25%" align="right"><FONT COLOR="#FFFFFF"><b>Despatch Date</b></FONT></td>
</tr>
</table>
<table BGCOLOR="#FFFFFF" columns="4" width="100%" RULES="rows">
<apex:repeat value="{!Despatch}" var="so" >
<tr>
<td width="15%" align="left" style=" windowtext 1.0pt; font-family: Arial; font-size: 10pt">
<apex:outputText value="{!so.PO_No__c}"/>
</td>
<td width="25%" align="center" style=" windowtext 1.0pt; font-family: Arial; font-size: 10pt">
<apex:outputText value="{!so.Invoice__r.Name}"/>
</td>
<td width="15%" align="center" style=" windowtext 1.0pt; font-family: Arial; font-size: 10pt">
<apex:outputText value="{!so.Quote_Quantity__c}" />
</td>
<td width="20%" align="center" style=" windowtext 1.0pt; font-family: Arial; font-size: 10pt">
<apex:outputText value="{!so.Product_Description__c}" />
</td>
<td width="25%" align="right" style=" windowtext 1.0pt; font-family: Arial; font-size: 10pt" >
<apex:outputText value="{0,date,dd'/'MM'/'yyyy}">
<apex:param value="{!so.Tentative_Despatch_Date__c}" />
</apex:outputText>
</td>
</tr>
</apex:repeat>
</table>
</apex:pageblock>
</apex:form>
</apex:page>
Error is in this bolck of markup code: Error Msg is: Unknown property 'OrderStatus.POWrapperClass.PO_No__c'
VISUALFORCE COMPONENT:
<apex:component controller="OrderStatus" access="global">
<p>
Please find attached the statement for {!name}
<br/>
<br/>
<font face="arial" size="2"/>
<br/>
<br/>
<div style="width:100%;background-color:#D1E1FF; height: 25px;">
<table style="width:100%;background-color:#D1E1FF">
<tr>
<td colSpan="2">
<b><font face="arial" size="2" color="Black">▼ Pending Orders</font></b>
</td>
</tr>
</table>
</div>
<br/>
<table border="0" columns="4" width="100%" style="position: relative; top: -2px;border:solid #767676;background-color:#767676">
<tr style="border:#000000;">
<td width="15%" align="left"><FONT COLOR="#FFFFFF"><b>PO Number</b></FONT></td>
<td width="16%" align="center"><FONT COLOR="#FFFFFF"><b>Balance Quantity</b></FONT></td>
<td width="20%" align="center"><FONT COLOR="#FFFFFF"><b>Product Name</b></FONT></td>
<td width="20%" align="center"><FONT COLOR="#FFFFFF"><b>Status</b></FONT></td>
<td width="29%" align="right"><FONT COLOR="#FFFFFF"><b>Planned Despatch Date/Time</b></FONT></td>
</tr>
</table>
<table BGCOLOR="#FFFFFF" columns="1" width="100%" RULES="rows">
<apex:repeat value="{!pending1}" var="s1">
<tr>
<td width="15%" style=" windowtext 1.0pt; font-family: Arial; font-size: 10pt">
<apex:outputText value="{!s1.PO_No__c}"/>
</td>
<td width="16%" style=" windowtext 1.0pt; font-family: Arial; font-size: 10pt">
<apex:outputText value="{!s1.Balance_Quantity__c}"/>
</td>
<td width="20%" style=" windowtext 1.0pt; font-family: Arial; font-size: 10pt">
<apex:outputText value="{!s1.Product_Description__c}" />
</td>
<td width="20%" style=" windowtext 1.0pt; font-family: Arial; font-size: 10pt">
<apex:outputText value="{!s1.Sales_Order_Status__c}" />
</td>
<td width="29%" style=" windowtext 1.0pt; font-family: Arial; font-size: 10pt" >
<apex:outputText value="{0,date,dd'/'MM'/'yyyy}">
<apex:param value="{!s1.Current_Despatch_Date_2__c}" />
</apex:outputText>
</td>
</tr>
</apex:repeat>
</table>
-->
<br/>
<br/>
<div style="width:100%;background-color:#D1E1FF; height: 25px;">
<table style="width:100%;background-color:#D1E1FF">
<tr>
<td colSpan="2
">
<b><font face="arial" size="2" color="Black">▼ Recent Despatches</font></b>
</td>
</tr>
</table>
</div>
<br/>
<table border="0" columns="4" width="100%" style="position: relative; top: -2px;border:solid #767676;background-color:#767676">
<tr style="border:#000000;">
<td width="15%" align="left"><FONT COLOR="#FFFFFF"><b>PO Number</b></FONT></td>
<td width="25%" align="center"><FONT COLOR="#FFFFFF"><b>Invoice Number</b></FONT></td>
<td width="15%" align="center"><FONT COLOR="#FFFFFF"><b>Quantity</b></FONT></td>
<td width="20%" align="center"><FONT COLOR="#FFFFFF"><b>Product Name</b></FONT></td>
<td width="25%" align="right"><FONT COLOR="#FFFFFF"><b>Despatch Date</b></FONT></td>
</tr>
</table>
<table BGCOLOR="#FFFFFF" columns="4" width="100%" RULES="rows">
<apex:repeat value="{!despatch1}" var="s2" >
<tr>
<td width="15%" style=" windowtext 1.0pt; font-family: Arial; font-size: 10pt">
<apex:outputText value="{!s2.PO_No__c}"/>
</td>
<td width="25%" style=" windowtext 1.0pt; font-family: Arial; font-size: 10pt">
<apex:outputText value="{!s2.Invoice__r.Name}"/>
</td>
<td width="15%" style=" windowtext 1.0pt; font-family: Arial; font-size: 10pt">
<apex:outputText value="{!s2.Quote_Quantity__c}" />
</td>
<td width="20%" style=" windowtext 1.0pt; font-family: Arial; font-size: 10pt">
<apex:outputText value="{!s2.Product_Description__c}" />
</td>
<td width="25%" style=" windowtext 1.0pt; font-family: Arial; font-size: 10pt" >
<apex:outputText value="{0,date,dd'/'MM'/'yyyy}">
<apex:param value="{!s2.Tentative_Despatch_Date__c}" />
</apex:outputText>
</td>
</tr>
</apex:repeat>
</table>
<br/>
<br/>
<br/>
Regards,<br/>
The Production Team.
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
<br/>Please help to respect the environment by not printing this email /
Pour contribuer comme au respect de l'environnement, merci de ne pas imprimer ce mail /
Bitte drucken Sie diese Nachricht nicht aus und helfen Sie so dabei, die Umwelt zu schtzen. /
Por favor ajude a a respeitar o ambiente nao imprimindo este correio electronico
</p>
</apex:component>
It's seems to me strange that you do only one class- for both the page and the component.
I never write it that it this way so I'm not sure what should be the behavior.
Usually, the component should have it's own apex class.
I.E :
public class cls_OrderStatus
{
public List<Sales_Order__c> pending;
public List<Sales_Order__c> getPending()
{
//fill the list pending
return pending;
}
}
Because when you call the email component it's using other instance of this class, and there all the data is empty, since the component doesn't call the class constructor.
At least, you have to provide get method for the list(s) that you using in the component (and be sure to fill the list with data in the component)
Ok thanks for your suggestion. Let me try and let you know.
Thanks for your priceless input. I was stuck in this since 5-6days.
getting an error message:
Unknown property 'OrderStatusComponentClass.POWrapperClass.PO_No__c'