I have a VF page which has a method in the controller that generates PDF and sends it out via email.
It's all working fine when I trigger off the method from a custom button on the page, which is the manual process from inside SF.
I need to automate the same process as we have an integrated mobile app that pushes up opportunities with line items. The problem is that I need to generate the PDF once the opportunity and all related line items are in.
Basically, the opportunity is inserted, then we retrieve the ID and then we push all the line items from the mobile app. Therefore we don't know when the last line item went in.
The thing is that I don't want to use another API call to update the opportunity once we push all line items from the mobile app as we have a bit of complexity in our API methods and that will get messy.
My first approach was to create a batch that will run hourly and will pick up the new opportunities that are created from the mobile app and marked with a checkbox. Half way through I realised that getContent() method is not allowed from a batch so I can't get the PDF and send out the emails. Then I did a bit of research and saw that same method cannot be called even from a trigger or a future method or whatever.
So far I saw one solution which is creating a webservice that will generate the PDF and send the email but I need to call the webservice via HTTP request, create remote sites etc. which will also get messy.
Any idea is appreciated!