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.


  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

  • If you're developing in Apex you can get the Session ID from UserInfo.getSessionId() and no need to hard code user credentials. There are a number of other posts covering this. Dec 16, 2013 at 10:23
  • using Userinfo class, we can get only logged in users session id. right?
    – goodForce
    Dec 16, 2013 at 11:08
  • Yes, thats true but what you can do is inject it into your scheduled/async class. Have a look at this post salesforce.stackexchange.com/questions/21435/… Dec 16, 2013 at 11:38
  • Here PDF needs to be created immediately after user approval. I have tried asyn c call using Future methods, but still no use. session id is empty only.
    – goodForce
    Dec 17, 2013 at 0:17
  • Thats why I said look at the post, you could pass it in to your future method from your trigger. Dec 17, 2013 at 7:48

1 Answer 1


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.

  • Hi, @deva can you please provide the step details how did you achieve this ?
    – Jarvis
    Jan 7, 2016 at 10:23
  • I am not using this solution anymore, instead I have created a batch job to create a PDF. I created a custom object to collect accepted record's id and the flag to check whether the PDF is created or not. the scheduled batch job checks this flag and creates the PDF if this flag is false. Now you can invoke getContent() method from Batch job also.
    – goodForce
    Apr 22, 2016 at 17:03

You must log in to answer this question.

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