2

I am trying to detect Quote PDF generation at the Quote level so that I can trigger update on a Quote related object. I know you cannot create triggers on the QuoteDocument object so is there any way to do this?

Is there any field on Quotes that gets updated when a Quote PDF is generated? I could use that as my trigger.

4
  • How is the quote being generated and sent to the customer? Is it generated via a button? Does that also send it to the customer? If the latter, you could use a trigger that fires on email. You could also add code to your button, but your button could presumably be pressed without sending the quote depending on how it's used.
    – crmprogdev
    Commented Mar 18, 2016 at 13:42
  • Thanks for responding. The Quote is generated using the standard 'Create PDF' button on the Quote page layout. The Quote PDF might or might not be E-mailed after it's generated hence relying on Email isn't an option. Is there no way to detect QuotePDF generation when using the Standard 'Quote Create' button? Commented Mar 18, 2016 at 14:39
  • All that button does is open a visual force page with renderAs="PDF". There's no DML that occurs that you could key off of when it's opened. Unless the page is saved, there's no event to trigger anything of off. And once you did, I don't believe that Quote would be updated since the PDF doesn't write to the Quote object. It's simply a document. It would entirely be a matter of how that document is saved that would present the opportunity to trigger further action.
    – crmprogdev
    Commented Mar 18, 2016 at 15:41
  • I only want my action to trigger when the QuotePDF is saved. Sorry if my words were confusing earlier. My process/flow needs to fire after the Quote PDF is saved to the QuoteDocument related list on Quotes. That PDF/document is saved using the native 'Save to Quote' button on the generated Quote PDF. Any ideas? Commented Mar 18, 2016 at 15:51

1 Answer 1

3

Here's one possibility that comes to mind if you were to write a trigger on Quote. There's no Quote History object, but there is the Quote PDF's related list that may have some kind of impact on the LastReferencedDate. Quote has two fields that might be of use: LastReferencedDate and LastViewedDate. LastReferencedDate would be the time your button accesses the Quote data when it prints the PDF.

The hitch to all this will be that I don't know if the LastReferenceDate will be updated again after the PDF document save happens or only when the data is accessed to generate the PDF. You'll need to test this behavior to see.

If your trigger detected a change in the LastReferencedDate, then ran a query that also found a new QuoteDocument for the same QuoteId record with a similar CreatedDate (you'd need to be loose with your criteria here as referenced vs save could be substantial), that could be an indicator that you have new QuoteDocument for that record.

To do this properly, you'd likely need to have a custom object that holds your previous values (think of it as a trigger.old) for QuoteDocuments you query that stores it by QuoteId. That would be the only way I can think of to ensure you knew this was a new document since the last time the trigger had fired.

You'd also want to compare other fields on Quote to make certain the trigger wasn't being fired for other reasons before deciding whether to run your query or on which records to run it. This is one general approach to trying to solve the problem you describe using a trigger that comes to mind at the moment.

2
  • Well this certainly helps. Thanks for taking the time and effort to write this. Much appreciated! Commented Mar 18, 2016 at 18:01
  • an alternative approach is to use the 'View Controller' trick wherein you put a VF page on your Quote page standard layout; the associated controller extension interrogates the QuoteDocuments related list and compares the highest lastmodifiedDate against a quote custom field; if greater, then you know there is a new quoteDocument and you can take action accordingly
    – cropredy
    Commented Mar 18, 2016 at 21:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .