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

List has no rows for assignment to SObject with getContent() from pdf
I want to create a pdf from a cutom button click and then attach it to the correspondening Object record. I have the following code for the apex controller for this:
I get List has no rows for assignment to sObject error in the line
public class attachPDFToTimeRecord { private final TimeRecords__c a; //TimeRecords object //constructor public attachPDFToTimeRecord(ApexPages.StandardController standardPageController) { a = (TimeRecords__c)standardPageController.getRecord(); //instantiate the TimeRecord object for the current record } //method called from the Visualforce's action attribute public PageReference attachPDF() { //generate and attach the PDF document PageReference pdfPage = Page.Invoice_Matter; //create a page reference to our Invoice_Matter Visualforce page Blob pdfBlob = pdfPage.getContent(); //get the output of the page, as displayed to a user in a browser Attachment attach = new Attachment(parentId = a.Id, Name = 'pdfAttachmentRecord.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 TimeRecord 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 get List has no rows for assignment to sObject error in the line
Blob pdfBlob = pdfPage.getContent();Can anyone help my resolve this error?
Error is because you need to pass Record Id into the VF page. Use below code.
Let me know the outcomes.
Thanks!
AMit Singh
All Answers
Error is because you need to pass Record Id into the VF page. Use below code.
Let me know the outcomes.
Thanks!
AMit Singh