You need to sign in to do that
Don't have an account?

Call Apex Class from Trigger after Update on Object
Hello everyone,
I guess this is as standard as it gets but I still struggle as newby in apex classes and triggers.
I have an apex class that - as for now - is being invoked by a process builder. But in regards of performance I want to switch to an apex trigger.
Here is the class:
Public class generateQuotePdfDocumentByTrigger{ //https://github.com/Rakeshistom/Auto-Generates-Quote-PDF public static void QuoteCreate (List<Id> quoteIds) { //Initialize the quote url String quoteUrl = '/quote/quoteTemplateDataViewer.apexp?'; //Get the Quote Template Id from Custom Settings String quoteTemplateId = Label.QuoteTemplateId; //List variable to get all the Quote Documents List<QuoteDocument> lstQuoteDoc = new List<QuoteDocument>(); if(!quoteIds.isEmpty() && quoteIds.size() > 0) { for(Id quoteId :quoteIds) { //Construct the quote URL to generate PDF quoteUrl += 'id=' + quoteId; quoteUrl += '&headerHeight=197&footerHeight=80'; quoteUrl += '&summlid=' + quoteTemplateId; //call the quote url PageReference pageRef = new PageReference(quoteUrl); //get the quotePdf Blob quoteBlob; if(Test.isRunningTest()) { quoteBlob = Blob.valueOf('Generate Pdf'); } else { quoteBlob = pageRef.getContentAsPDF(); } //initialze the QuoteDocument to hold the quote pdf for insertion QuoteDocument quoteDoc = new QuoteDocument(); quoteDoc.Document = quoteBlob; quoteDoc.QuoteId = quoteId; lstQuoteDoc.add(quoteDoc); } } if(!lstQuoteDoc.isEmpty() && lstQuoteDoc.size() > 0) { Database.insert(lstQuoteDoc); } } }What I like the trigger to do is the following:
After "Create_PDF__c" is set to "true" - invoke the apex class.
This is what I got so for but yeah...
Error: Compile Error: Method does not exist or incorrect signature: void generateQuotePdfDocumentByTrigger() from the type CreatePDFQuote_JTo at line 7 column 9
trigger CreatePDFQuote_JTo on Quote (after update) { for(Quote currentQuote : Trigger.New) { if(currentQuote.Create_PDF__c == true ) { generateQuotePdfDocumentByTrigger(); } } }
Thanks in Advance!
unfortunately I am running in the following error:
The flow tried to update these records: null. This error occurred: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY: CreatePDFQuote_JTo: execution of AfterUpdate caused by: System.VisualforceException: Getting content from within triggers is currently not supported. Class.generateQuotePdfDocumentByTrigger.QuoteCreate: line 33, column 1 Trigger.CreatePDFQuote_JTo: line 15, column 1.
It is now working and the class does what it should meaning creating PDFs. However I am creating 3 PDFs now at once for 1 quote. Is this due to (before update) ?