You need to sign in to do that
Don't have an account?
Devmen
records are not visible in Visualforcepage when send as email attachment.
Hi,
Im using two Vf pages and 1 custom controller.first page has send button.When i click send button it should send second page as email attachment.In attachments records are not visible. Could anyone resolve this?
Thanks
Im using two Vf pages and 1 custom controller.first page has send button.When i click send button it should send second page as email attachment.In attachments records are not visible. Could anyone resolve this?
public Pagereference sendmail(){ pagereference pdf; orderflag=true; OrdList=[selectid,name,Total_Quantity_in_Sets__c,Order_Amount__c,Order_Date__c,Distributor__r.Email__c,Retailer_O__r.name,Order_Type__c,(select id,name,Quantity__c,Remarks__c,MRP__c,Product__r.Item_Code__c,Product__r.Remarks__c,Product__r.Tube_Weight_gm__c,Product__r.Unit_In_Dozens__c,Product__r.name from Order_Line_Items__r) from Order_C__c where Order_Date__c>=:fromdate1 AND Order_Date__c<=:todate1 AND Distributor__c=:Selecteddistri AND Order_Type__c=:'Secondary Order'];List<String> lstselectedRecordIds = new List<String>();for(Order_C__c o:OrdList){ wrapOrder w=new wrapOrder(); w.Ord=o; system.debug('ORRRRRRRRRRRDER'+w.Ord); w.OLlist1=o.Order_Line_Items__r; w.Retailername=o.Retailer_O__r.name;WrapList.add(w); system.debug('WRRRRRRRRRRAPLIST'+WrapList); }for(wrapOrder wo:WrapList){ for(Order_Line_Item_C__c o:wo.OLlist1){ ollist.add(o); system.debug('OLLLLLLLLIST'+ollist.add(o)); wrapOrderSummary w1=new wrapOrderSummary(); w1.productname=o.Product__r.name; w1.Quant=0; w1.price=0; mapWS1.put(o.Product__r.name,w1); }}for(Order_Line_Item_C__c ws:ollist){ if(mapWS1.containsKey(ws.Product__r.name)){mapWS1.get(ws.Product__r.name).Quant= mapWS1.get(ws.Product__r.name).Quant+ws.Quantity__c; mapWS1.get(ws.Product__r.name).price= mapWS1.get(ws.Product__r.name).price+ws.MRP__c;} }for(wrapOrderSummary w2:mapWS1.Values()) { WSumlist.add(w2);}for(Integer i=0;i<OrdList.size();i++){ lstselectedRecordIds.add(OrdList[i].Id); system.debug('ORDERIDDDDDDDDD'+lstselectedRecordIds); } string s=''; for(Integer i=0;i<lstselectedRecordIds.size();i++)if(i<lstselectedRecordIds.size()-1) s=s+lstselectedRecordIds[i]+':'; else s=s+lstselectedRecordIds[i];}acc1=[select id,name,Email__c from Account where id=:selecteddistri]; system.debug('ACCCCCCCCCCC'+acc1);user u=[select id,name,manager.email,manager.name,managerid from user whereid=:userinfo.getuserid()]; if(u.managerid!=null){ u1=[select id,name,email,manager.email from user where id=:u.managerid ];} try { Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment(); Blob body; // Who you are sending the email to List<String> sendTo = new List<String>(); if(acc1.Email__c!=null){ system.debug('EMMMMMMMMMMMMMMAIL'+acc1.Email__c); sendTo.add(acc1.Email__c); } mail.setToAddresses(sendTo);mail.setSubject('Sample'); mail.setHtmlBody('<p>Dear '+u.manager.name+', <br/><br/> The below are the orders in between '+fromdate1.day()+'-'+fromdate1.month()+'-'+fromdate1.year()+' to '+todate1.day()+'-'+todate1.month()+'-'+todate1.year()+'.<br/><br/></p>'pdf= Page.Distributororderpdf; system.debug('PDDDDDDDF'+pdf); body = pdf.getContentAsPDF(); attach.setContentType('application/pdf'); attach.setFileName('DistributorOrder.pdf'); attach.setBody(body); mail.setFileAttachments(new Messaging.EmailFileAttachment[] { attach }); Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});emailflag=true; }catch(Exception e) {} return pdf; }
1st VF page: <table width="100%"><tr><td> <div align="center"> <apex:outputpanel id="op3" rendered="{!emailflag=false}"><apex:commandButton value="Send" action="{!sendmail}" styleclass="slds-button slds-button_neutral" /> <apex:commandButton value="Cancel" action="{!Cancel}" styleclass="slds-button slds-button_neutral" /> </apex:outputpanel> </div> </td></tr></table> 2nd VF page <table border="1" cellspacing="0" cellpadding="3" width="80%" rendered="{!orderflag=true}" > <apex:variable value="{!1}" var="count"/> <apex:repeat value="{!OrdList}" var="w1"> <tr> <td align="left" style="text-align:left;font-weight:bold" colspan="4" > Retailer Name: {!w1.Retailer_O__r.name} </td> </tr> <tr> <td align="center" style="text-align:center;font-weight:bold;" width="25%">Order Number : {!w1.name}</td> <td align="center" style="text-align:center;font-weight:bold;" width="25%">Order Date : <apex:outputtext value="{0,date,MM/dd/yy}"><apex:param value="{!w1.Order_Date__c}" /></apex:outputtext></td> <td align="center" style="text-align:center;font-weight:bold;" width="25%">Total Qty : {!w1.Total_Quantity_in_Sets__c}</td> <td align="center" style="text-align:center;font-weight:bold;" width="25%">Total Value :{!w1.Order_Amount__c}</td> </tr> <tr> <td colspan="4"> <table> <tr> <td style="text-align:center;font-weight:bold;" width="12%"></td> <td style="text-align:center;font-weight:bold;" width="12%">Product Code</td> <td style="text-align:center;font-weight:bold;" width="12%">Product Name</td> <td style="text-align:center;font-weight:bold;" width="12%">Price</td> <td style="text-align:center;font-weight:bold;" width="12%">Quantity</td> </tr> <apex:repeat value="{!ollist}" var="o"> <tr> <td style="text-align:center;font-weight:bold;" width="12%"></td> <td width="12%" style="text-align:center;">{!o.Product__r.Item_Code__c}</td> <td width="12%" style="text-align:center;">{!o.Product__r.Name}</td> <td width="12%" style="text-align:center;">{!o.MRP__c}</td> <td width="12%" style="text-align:center;">{!o.Quantity__c}</td> </tr> </apex:repeat></table> </td> </tr> <apex:variable value="{!Count+1}" var="count"/> </apex:repeat> </table>
Thanks
Gulafsha Mohammed
Can you post your second vf page also?
Devmen
Thanks for the reply .Below is second Vf page which is sending as attachment
Devmen
Hi,
Now if I change the method into pagereference page is displaying with records. In attachment page is blank. Any idea is to resolve this?