<div class="separator" style="clear: both; text-align: left;">However the only way to post a document is either via included visualforce pages or via the FinancialForce API. However I’ve done the hard part and written an apex trigger (with test code!) for the sales invoice object that uses a checkbox to post the document via the API.</div><div class="separator" style="clear: both; text-align: center;">
</div><div class="separator" style="clear: both; text-align: left;">First we’ll need to create a checkbox on the sales invoice object that controls the posting of a document, like so:</div>
and then use this field to control posting of the document with a trigger like this one:
and of course you’ll need a test class to deploy it to production:
Once deployed you can check the “Action: Post Invoice” box via the user interface, workflow, or any other means (note that this implementation is likely to hit governor limits if you check more than 3-4 in a single DML transaction, as such time based workflow is not advised. The limits may be lower for especially complex invoices.).
As with any FinancialForce API integration an API key is needed, and your current company must be set to the same company that the invoice is in. Contact support to get a free API key if you don’t have one.
One final disclaimer that despite working for FinancialForce this code and post were done in my own time and are not officially provided or endorsed by FFDC.