You need to sign in to do that
Don't have an account?
Please Help!! - Auto Increment File Name
Hi All,
Need help please. Im not a developer and so struggling with the followng issue:
I have created a custom object which behaves in a similer manner as the "Quote" standard object and so i am able to produce Quotes in PDF by clicking on a custom button called "Create PDF". However, when I produce the PDF file i would like to incremant the file name by '1' each time. For example, when the "Create PDF" button is clicked the file name should be Quote_V1.pdf should then become Quote_V2.PDF, then Quote_V3.PDF etc etc
Not sure how to do this. Please see a part of my apex code below which is where I think i need to make my modification :
Public PageReference SaveQuote() { try { String QId = ApexPages.currentPage().getParameters().get('id'); dealerQuotation = [SELECT Id,Name FROM Dealer_Quotation__c WHERE Id = :QId]; PageReference pdf = Page.Dealer_Quotation; pdf.getParameters().put('id',Qid); Attachment attach = new Attachment(); Blob body; try { body = pdf.getContentAsPdf(); } catch(Exception ex) { body = Blob.ValueOf('Error occured in page'); } string name; if(dealerQuotation != null) { name = dealerQuotation.Name + '.pdf'; } else { name = 'Quotation.pdf'; } attach.body = body; attach.Name = name; attach.IsPrivate = false; attach.ParentId = QId; insert attach; PageReference redirectPage = New PageReference('/' + QId); redirectPage.setRedirect(true); return redirectPage; } catch(Exception ex) { ApexPages.Message exMsg = new ApexPages.Message(ApexPages.Severity.ERROR, ex.getMessage()); ApexPages.AddMessage(exMsg); return null; } }
Any help would be greatly appreciated!
All Answers
You could create a custom number field on your Dealer Quotation object that tracks the number of created pdfs such that each time the button is clicked, the value is incremented by 1, and you can use this value in the quote names. Just set the default value to 1 for the custom field, and increment after attachment is inserted.
Thanks for the response.
The pds's are saved to related list "Notes and Attachments" and so any idea how i track the number of pds created?
That worked perfectly! Thank you!