I have created a VF page for generating invoice and from that VF page i am invoking a PDF VF page. In invoice VF page i saved the invoice and pass the parameter to PDF page and trying to display it. I have a Print button to call the PDF page.
<apex:commandButton onclick="openPrint()" value="Print" rendered="{!ShowHidePrint}" reRender="buttonblock"/>
on the click of the print button it call a javascript from where it get redirect to PDF Page.
` <script>
function openPrint()
{
window.open("{!sfdcBaseURL}","mywindow","menubar=1,resizable=1,width=750,height=350");
}
</script>`
their is a method called conform invoice which is used to save invoice and in the confor invoice method i am populating the {!sfdcBaceURL} the url to PDF page. Till here it works properly. Now i need to attach the generated PDF to the generated invoice. for that i created a method called attach and call the method in VF conform invoice method.
public PageReference attachPDF()
{
system.debug('inside attachant ');
system.debug('invoice id ' + invCrdNoteforInsert.id );
system.debug('Invoice No in attachment ' + invCrdNoteforInsert.Name);
PageReference redirect = new PageReference (sfdcBaseURL);
/*redirect.getParameters().put('invId', invCrdNoteforInsert.id );
redirect.getParameters().put('expId', expID );
redirect.getParameters().put('grandT', string.valueof(grandTotal ));
redirect.getParameters().put('ExpgrandTotal', string.valueof(ExpgrandTotal) );
redirect.getParameters().put('TaxFlagAmt', string.valueof(TaxFlagAmt) );
redirect.getParameters().put('pjtName', project ); */
//return redirect;
system.debug('redirect body ' + redirect);
insertedInvoiceId = invCrdNoteforInsert.id ;
applicationpdf = new Attachment();
system.debug('redirect body after attatchent' + redirect);
system.debug('redirect body after attatchent Body' + redirect);
applicationpdf.ContentType = '.pdf';
applicationpdf.Name = 'Invoice - ' + String.valueof(Datetime.now());
applicationpdf.Name += '.pdf';
system.debug('inserted Invoice Id ' + insertedInvoiceId);
applicationpdf.ParentId = insertedInvoiceId;
applicationpdf.Body = redirect.getContentAsPdf();
insert applicationpdf;
system.debug('inserted Invoice ' + applicationpdf);
insertedInvoiceId = null;
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Info, 'PDF has been attached!'));
return null;
}
but when i call this method i am getting a error called list has no row to assign. The invoice is not generated and it is getting roll backed. Can any one guide me what is the issue for getting the roll back when i try to attach the pdf. It works when i created a new command button and calling the attach method. The problem accrues when attach method called from conform invoice method. Does any body know what is the issue and how to solve it.