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

Google Docs, Notes, & Attachments ,,,Title Name

public void attach() {
            Attachment myAttach = new Attachment();
            myAttach.ParentId = ApexPages.currentPage().getParameters().get('id');
            System.debug('Id: ' + ApexPages.currentPage().getParameters().get('id'));
            List<Attachment> at=[Select id from Attachment where parentId=:myAttach.ParentId];
            Integer c=at.size()+1;
   =D.Account__r.Name +''+ 'License Version' + c +'.pdf';
            PageReference psPdf = new PageReference('/apex/Quotation?id=' + ApexPages.currentPage().getParameters().get('id'));
            myAttach.body = psPdf.getContentAsPdf();

            insert myAttach;


In this i want to get the Google Docs, Notes, & Attachments ,,,Title Name when i attach Quotation by clicking the button

D.Account__r.Name +''+ 'License Version' + c +'.pdf';==aaa1.pdf


and when i attach manually finaldraft.doc

and when again i attach D.Account__r.Name +''+ 'License Version' + c +'.pdf';==aaa3.pdf but it should be aaa2.pdf



its urgent can u help me


Hi Anil,


As per my understanding, you want to follow common naming for documents which are uploaded through apex(commandbutton). Your apex code should not consider the files attached mannually by user.


If It so, Then while qerying attachment put filter, for example

List<Attachment> at=[Select id,name from Attachment where  parentId=:myAttach.ParentId

  AND  name like :'%'+D.Account__r.Name+'%'];


In this way you will get attachments which are uploaded through apex and you can increase version and provide the file name.


Hope this will help you.

[If it solves your problem, please mark it as solution]