You need to sign in to do that
Don't have an account?
Mathew Andresen 5
First time I run process email is blank, second time email has data
Hi,
This is really wierd. I have an action that triggers a summary email to be sent when triggered. The first time I click the action button the email gets sent but is blank. The second time I click it the email is sent but has data in it. I can't think what could possibly cause behavior like that.
This is the section
of code where I send the summary email (I can provide the rest if needed)
and here is the visualforce page I call for the tempalte
Thanks,
This is really wierd. I have an action that triggers a summary email to be sent when triggered. The first time I click the action button the email gets sent but is blank. The second time I click it the email is sent but has data in it. I can't think what could possibly cause behavior like that.
This is the section
try { PageReference displayPage = page.BottlingSummaryEmail_page; Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage(); String[] toAddresses = new String[] {}; toAddresses.add(userEmail); Blob body; string htmlBody; try { // returns the output of the page as a blob body = displayPage.getContent(); system.debug('body should be fine'); // need to pass unit test -- current bug } catch (VisualforceException e) { system.debug('in the catch block'); body = Blob.valueOf('Some Text'); } htmlBody = body.toString(); email.setHtmlBody(htmlBody); email.setToAddresses(toAddresses); email.setSubject('Bottling Summary for '); // + dateString); Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email}); } catch (exception e) { system.debug ('TastingRecap_class *** error in the send email and error = ' + e);}
of code where I send the summary email (I can provide the rest if needed)
and here is the visualforce page I call for the tempalte
<apex:repeat value="{!botLotMap}" var="shift"> <h1> Bottling Summary for Shift {!shift} </h1> <table width="100%"> <th>Shift</th><th>Change Over</th><th>Operation</th> <th>Client</th><th>Brand</th><th>Cases</th><th>Cases per Hour</th><th>Notes</th> <apex:repeat value="{!botLotMap[shift]}" var="v" > <tr> <td><apex:outputtext value="{!botLotMap[shift][v].Bottling_Shift__r.Bottling_Shift__c}" /></td> <td><apex:outputtext value="{!botLotMap[shift][v].Type_of_Changeover__c}" /> </td> <td><apex:outputtext value="{!botLotMap[shift][v].Labeled_Bottled__c}"/></td> <td><apex:outputtext value="{!botLotMap[shift][v].Client_Lookup__r.name}" /></td> <td><apex:outputtext value="{!botLotMap[shift][v].Brand__c}"/></td> <td><apex:outputtext value="{!botLotMap[shift][v].Actual_Bottled__c}"/> </td> <td><apex:outputtext value="{!botLotMap[shift][v].Cases_Per_Hour__c}"/></td> <td><apex:outputtext value="{!botLotMap[shift][v].Notes__c}"/></td> </tr> </apex:repeat> <tr><td colspan="4">Total</td><td>{!totalCasesBottled[shift]}</td><td></td><td></td><td></td></tr> </table> </apex:repeat> </apex:page>
Thanks,
VF - SendPageAsEmail
Apex Class
VF Page
Another workaround which I can suggest is create Visualforce email template and use a component inside the template to generate your body dynamically. Please follow my answer to this blog post for the sample code - https://developer.salesforce.com/forums/ForumsMain?id=906F0000000D6IfIAK
In the template there you wont have to send as attachment but as a body so just your template would look like below:
Hope it helps.
All Answers
Does BottlingSummaryEmail_page accept any parameter like id or something ? when you hit that page directly using /apex/BottlingSummaryEmail_page does it show you any data ?
Can you try doing this-
the BottlingSummaryEmail_page doesn't take any parameters. It just gets the data from the BotDay controller. So if I hit the page directly there is no data to show. I tried as you suggested, but still no data the first time, but data the second. Note that (String)pageContent didn't work, it produced an error
https://www.dropbox.com/sh/405650trfncq9cz/AACLHrNMEi8mdTZNKQzjeaVda?dl=0
full code for the page below
VF - SendPageAsEmail
Apex Class
VF Page
Another workaround which I can suggest is create Visualforce email template and use a component inside the template to generate your body dynamically. Please follow my answer to this blog post for the sample code - https://developer.salesforce.com/forums/ForumsMain?id=906F0000000D6IfIAK
In the template there you wont have to send as attachment but as a body so just your template would look like below:
Hope it helps.