You need to sign in to do that
Don't have an account?
Hi Everyone, I need to bulkify my apex trigger code, can anyone help me..
Trigger: trigger PDFGenrate on Opportunity (after insert, after update) { Set<Id> OppIds= new Set<Id>(); for(Opportunity opp: trigger.new){ if(opp.StageName=='Closed Won'){ OppIds.add(Opp.Id); } }OpportunityPdfController.pdfGenration(OppIds); } Trigger Handler: public class OpportunityPdfController { @future(callout=true) public static void pdfGenration(Set<Id> OppIds){ List<Sobject> attachmentlist = new List<Sobject>(); List<Sobject> ContentDocLink = new List<Sobject>(); for(Id OppId: OppIds){ Blob body; PageReference pdf = new PageReference('/apex/PrintPDF'); pdf.getParameters().put('Id',OppId); ContentVersion cv=new ContentVersion(); try{ body=pdf.getContentAsPDF(); }catch (Exception e) { body = Blob.valueOf('Text'); system.debug(e.getMessage()); } cv.PathOnClient= 'Invoice'+'.pdf'; cv.Title= 'Invoice'; cv.IsMajorVersion = true; cv.VersionData=body; attachmentlist.add(cv); // } // if(attachmentlist.size()>0){ insert attachmentlist; Id conDocId = [SELECT ContentDocumentId FROM ContentVersion WHERE Id =:cv.Id].ContentDocumentId; system.debug(conDocId); ContentDocumentLink cdl = New ContentDocumentLink(); cdl.LinkedEntityId = OppId; cdl.ContentDocumentId = conDocId; cdl.shareType = 'V'; ContentDocLink.add(cdl); insert ContentDocLink; } } }
Please use the code below bulkified. The only change I made instead of Attachment, I used ContentVersion.
Let me know.
All Answers
Please use the code below bulkified. The only change I made instead of Attachment, I used ContentVersion.
Let me know.
Hi Abdul ,
Thank for your response, can you please also help me to send this attachment file on account email address.