When an opportunity meets certain criteria, I need to generate a PDF and attach it to the opportunity record. While it works on existing records, I'm running into a problem on new ones.
How I'm doing it:
- Whenever an opportunity is created or updated the Process Builder launches a Visual Flow
- The Flow configures a parameter string (couldn't do it in PB) and calls an apex module.
- The apex module renders a VF page generates the PDF
- The page's controller attaches the PDF to the opportunity.
Though a bit round-abut this is working perfectly for existing opportunities and gets me around the limitation that triggers can't generate PDFs.
However, it's crashing on new opportunities. I've determined the cause to be that the Attachment object requires the ParentID field represent a known object. While I do have the Object's ID (more specifically, what it will be), it's not yet committed to storage so inserting the new attachment doesn't recognize it and crashes. (doing a query for the opportunity by id yields zero results)
Any suggestions on how to get out of this knot?
I'm considering using a scheduled job so it unlinks the activities
from one another - is there a way to schedule PB scripts or Flows?
Would getting into the pilot for Workflows calling Flows solve this
timing issue? (I suspect not)