You need to sign in to do that
Don't have an account?
Meggan Landis 11
New Generate and Attach pdf button works in production but not in Community portal
Hi all,
I have a button that is working fine in production; the problem however, is that I need it to work in the Community portal. The button is on the page, but I am getting and Invalid Page error when I try to execute it. The button is gnerating a pdf and attaching it to notes and attachments. I have the following VF pages and apex code that are working for me in production. Any help would be greatly appreciated.
VF Page:
<apex:page standardController="Box_Request__c" renderAs="pdf">
<apex:stylesheet value="{!URLFOR($Resource.psfStyle2,'psf.css')}"/>
<div align="right"><strong>Date</strong>: {!DAY(Today())} {!CASE(MONTH(Today()), 1, 'January', 2, 'February', 3, 'March', 4, 'April', 5, 'May', 6, 'June', 7, 'July', 8, 'August', 9, 'September', 10, 'October', 11, 'November', 12, 'December', 'Unknown')} {!YEAR(Today())}</div>
<center>
<h1>PACKING SLIP</h1>
</center>
<table>
<b>SHIP TO DETAILS:</b>
<hr/>
<tr><th>Shipping Address: </th>
<td><apex:outputText escape="false" value="{!Box_Request__c.ShippingAddressVF__c}"/></td>
</tr>
<tr><th>ATTN: </th>
<td><apex:outputText value="{!Box_Request__c.Attn__c}"/></td>
</tr>
<br></br>
<table style="font:10pt">
<b>ORDER DETAILS:</b>
<hr/>
<apex:pageBlock mode="maindetail">
<apex:pageBlockTable value="{!Box_Request__c.Box_Request_Orders__r}" var="su"
columnsWidth="85%,10%,5%">
<p Style="font-size:6px;">
<apex:column headerValue="Ordered Item" >
<apex:outputText value="{!su.Line_Item_Description__c}"/></apex:column>
<apex:column headerValue="Qty" >
<apex:outputField value="{!su.Qty__c}"/></apex:column>
<apex:column headerValue="Unit" >
<apex:outputText value="{!su.Unit_of_Measure_Note__c}"/></apex:column></p>
</apex:pageBlockTable>
</apex:pageBlock>
</table>
<br></br>
<br></br>
</table>
</apex:page>
VF Page:
<apex:page action="{!attachPDF}" extensions="attachPDFToBoxRequest" standardController="Box_Request__c">
apex:pageMessages ></apex:pageMessages><!-- included for display of errors should they occur -->
<apex:detail inlineEdit="true" relatedList="true"></apex:detail> <!-- included so Opportunity detail information is visible when errors occur -->
</apex:page>
APEX CLASS:
public class attachPDFToBoxRequest {
private final Box_Request__c a; //BR
//constructor
public attachPDFToBoxRequest(ApexPages.StandardController standardPageController) {
a = (Box_Request__c)standardPageController.getRecord();
}
//method called from the Visualforce's action attribute
public PageReference attachPDF() {
//generate and attach the PDF document
PageReference pdfPage = Page.pdfBoxRequest;
pdfPage.getParameters().put('Id', a.Id);
Blob pdfBlob; //create a blob for the PDF content
if (!Test.isRunningTest()) { //if we are not in testing context
pdfBlob = pdfPage.getContent(); //generate the pdf blob
} else { //otherwise, we are in testing context and getContent() create the blob manually
pdfBlob = Blob.valueOf('Some Text');
}
Attachment attach = new Attachment(parentId = a.Id, Name = 'PackingSlip.pdf', body = pdfBlob); //create the attachment object
insert attach; //insert the attachment
//redirect the user
PageReference pageWhereWeWantToGo = new ApexPages.StandardController(a).view(); //we want to redirect the User back to the detail page
pageWhereWeWantToGo.setRedirect(true); //indicate that the redirect should be performed on the client side
return pageWhereWeWantToGo; //send the User on their way
}
}
I have a button that is working fine in production; the problem however, is that I need it to work in the Community portal. The button is on the page, but I am getting and Invalid Page error when I try to execute it. The button is gnerating a pdf and attaching it to notes and attachments. I have the following VF pages and apex code that are working for me in production. Any help would be greatly appreciated.
VF Page:
<apex:page standardController="Box_Request__c" renderAs="pdf">
<apex:stylesheet value="{!URLFOR($Resource.psfStyle2,'psf.css')}"/>
<div align="right"><strong>Date</strong>: {!DAY(Today())} {!CASE(MONTH(Today()), 1, 'January', 2, 'February', 3, 'March', 4, 'April', 5, 'May', 6, 'June', 7, 'July', 8, 'August', 9, 'September', 10, 'October', 11, 'November', 12, 'December', 'Unknown')} {!YEAR(Today())}</div>
<center>
<h1>PACKING SLIP</h1>
</center>
<table>
<b>SHIP TO DETAILS:</b>
<hr/>
<tr><th>Shipping Address: </th>
<td><apex:outputText escape="false" value="{!Box_Request__c.ShippingAddressVF__c}"/></td>
</tr>
<tr><th>ATTN: </th>
<td><apex:outputText value="{!Box_Request__c.Attn__c}"/></td>
</tr>
<br></br>
<table style="font:10pt">
<b>ORDER DETAILS:</b>
<hr/>
<apex:pageBlock mode="maindetail">
<apex:pageBlockTable value="{!Box_Request__c.Box_Request_Orders__r}" var="su"
columnsWidth="85%,10%,5%">
<p Style="font-size:6px;">
<apex:column headerValue="Ordered Item" >
<apex:outputText value="{!su.Line_Item_Description__c}"/></apex:column>
<apex:column headerValue="Qty" >
<apex:outputField value="{!su.Qty__c}"/></apex:column>
<apex:column headerValue="Unit" >
<apex:outputText value="{!su.Unit_of_Measure_Note__c}"/></apex:column></p>
</apex:pageBlockTable>
</apex:pageBlock>
</table>
<br></br>
<br></br>
</table>
</apex:page>
VF Page:
<apex:page action="{!attachPDF}" extensions="attachPDFToBoxRequest" standardController="Box_Request__c">
apex:pageMessages ></apex:pageMessages><!-- included for display of errors should they occur -->
<apex:detail inlineEdit="true" relatedList="true"></apex:detail> <!-- included so Opportunity detail information is visible when errors occur -->
</apex:page>
APEX CLASS:
public class attachPDFToBoxRequest {
private final Box_Request__c a; //BR
//constructor
public attachPDFToBoxRequest(ApexPages.StandardController standardPageController) {
a = (Box_Request__c)standardPageController.getRecord();
}
//method called from the Visualforce's action attribute
public PageReference attachPDF() {
//generate and attach the PDF document
PageReference pdfPage = Page.pdfBoxRequest;
pdfPage.getParameters().put('Id', a.Id);
Blob pdfBlob; //create a blob for the PDF content
if (!Test.isRunningTest()) { //if we are not in testing context
pdfBlob = pdfPage.getContent(); //generate the pdf blob
} else { //otherwise, we are in testing context and getContent() create the blob manually
pdfBlob = Blob.valueOf('Some Text');
}
Attachment attach = new Attachment(parentId = a.Id, Name = 'PackingSlip.pdf', body = pdfBlob); //create the attachment object
insert attach; //insert the attachment
//redirect the user
PageReference pageWhereWeWantToGo = new ApexPages.StandardController(a).view(); //we want to redirect the User back to the detail page
pageWhereWeWantToGo.setRedirect(true); //indicate that the redirect should be performed on the client side
return pageWhereWeWantToGo; //send the User on their way
}
}