[SalesForce] How to create and attach PDF upon approval through standard email approval process

I have a scenario PDF needs to be created and attached the same to custom object upon user approval. Users will approve through email approval process.

Challenges:

  1. Create a PDF using visualforce page

    a.Salesforce has limitation to use getContent() or getContentAsPDF()
    methods in trigger & callout.

    b. We are using same VF page in other button clicks to view PDF.

  2. Getting Seession ID

I found following methods to create PDF:

  1. Web Service

    a. Once user approved the record, Trigger will invoke the webservice
    using callout.

    b. Getting session id with the help of partner wsdl. (Hardcoded
    username & password)

    c. It works now, but user login credentials are hard coded, what is
    the best practice for this?

  2. Email Service

    a. Once user approved the record, PDF will be sent as an
    attachment(visualforce email template) using email alert.
    b. Created email service to parse the inbound email and attach PDF
    to Custom object

    c. Sending Empty email

Any other suggestion to generate PDF which can fit into this scenario. Please advise

Best Answer

I managed to resolve my self.

I am using web service to create a PDF and invoking the same in Trigger using Future Method.

Since user is approving the record using email approval, user session is not available. To get the user session i am using on dummy user and getting the User session using Partner WSDL.

Thanks for all.