function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
AmandaSilberAmandaSilber 

Generate PDF Invoice & Create Invoice Tracking Record & Attach Generated PDF to New Record??

 

 

 

I have tried so many different things to try to get this accomplished and I just can't figure it out! It's driving me crazy, I've spent so many hours getting error after error.

So, any help would be greatly appreciated!!

I have a custom button on the parent record that 1. Creates a .pdf through a visualforce page using data within the parent record (Invoice) and 2. Creates a child record "Partnership Invoice Tracking".

I would like a third action to fire as well - attach the created .pdf to the newly created Partnership Invoice Tracking record.  I've been so close so many times, but kept getting " Expected ';' " errors.

Here is the code I have that performs the two above referenced actions:


________________________________________________________________________________

{!REQUIRESCRIPT("/soap/ajax/14.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/14.0/apex.js")}
var newRecords = [];

var PA = new sforce.SObject("Partnership_Account__c ");
var PAStatus__c = "{!Partnership_Account__c.Status__c }"
if(PAStatus__c == "Active")
{
window.open("{!URLFOR('apex/partnershipAccountpdf?id=' + Partnership_Account__c.Id )}");
}
else
{
alert('Only active Partnership Accounts will generate the Invoice. Please change the Status field value to Active in the Partnership Account record to generate the invoice.');
}




{!REQUIRESCRIPT("/soap/ajax/24.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/10.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/10.0/apex.js")}

// purpose: onClick() event handler
// author: Amanda Silber
// dated: November 2, 2012

var createList = [];
var copyPartnershipInvoiceTracking = new sforce.SObject("Partnership_Invoice_Tracking__c");
copyPartnershipInvoiceTracking.Partnership_Account__c = "{!Partnership_Account__c.Id}";
var tDate = sforce.internal.dateTimeToString(new Date());

//set name on record
copyPartnershipInvoiceTracking.Name = "{!Partnership_Account__c.Invoice_Number__c}";
copyPartnershipInvoiceTracking.Contract_Addendum_Type__c = "SRA";

createList.push(copyPartnershipInvoiceTracking);
sforce.connection.create(createList);

window.alert("Partnership Invoice Tracking Record Created");
parent.window.location.reload();

 

___________________________________________________________________________

Thank you in advance!!

Mohith Kumar ShrivastavaMohith Kumar Shrivastava

Was thinking what if we insert the generated Pdf as an attachment and related the attachment with the Custom object where you want may resolve the problem than using ajax

AmandaSilberAmandaSilber

Let me just say that in no way do I consider myself a developer. I dabble in it and I try really hard to learn it by writing and testing and reading blogs and developer guides. I would love to understand it better, but I don't have much time to take classes. 

 

That being said, I'm not sure of any other way to do it other than how I am currently.  Here is what I had for the 'attachment' code:

 

public PageReference savePdf() {
 
    PageReference pdf = Page.'partnershipAccountpdf;
    
// create the new attachment{
Attachment attach = new Attachment();
 
    // the contents of the attachment from the pdf
    Blob body;
    try {
        // returns the output of the page as a PDF
    	body = PartnershipAccountPdf.getContent();	
    } 
    attach.Body = body;

    // add the user entered name
    attach.Name = “Invoice" + copyPartnershipInvoiceTracking.Name”;
    attach.IsPrivate = false;

    // attach the pdf to the account
    attach.copyPartnershipInvoiceTracking = "{!Partnership_Invoice_Tracking__c.Id}";
    insert attach;
}