You need to sign in to do that
Don't have an account?
Monin Savant
Before creating attachment check if it doesn't exist
I am creating an attachment, but I want to check if it does not exist with the same name.
a = (Opportunity)standardPageController.getRecord(); PageReference pdfPage = new PageReference('/apex/myPage'); Opportunity b =[select Id, Name Invoice_Number__c from Opportunity where Id=:a.id]; Blob pdfBlob; Attachment attach = new Attachment( parentId = a.Id, Name = b.Name +'.pdf', body = pdfBlob); //create the attachment object insert attach;
I have added the parendId also in below query to filter the attachment based on Name and under particular opportunity... If you don't need the parentId check then remove the parentId in where condition.
List<Attachment> att = [ SELECT Name,ParentId FROM Attachment where Name =: existAttachname and parentId =: b.Id];
Please try the below code:
Thanks,
Maharajan.C