I have a trigger on a custom object which on certain conditions call a future method. The future method calls a Salesforce REST function. This rest function calls a PDF VF page, stores the body as an Attachment under the custom object. Since a REST function requires a session ID, we pass the Session ID using the UserInfo.getSessionId() function.
Everything works fine and the attachment is generated and attached with the proper details. However, when the record for the custom object is generated via Bulk API, the webservice call method gives an error called Unauthorized. The reason for this is I believe that the function doesn't get the proper SessionId.
Does the Bulk API do not generate a session Id which can be used again?
UserInfo.getSessionId()
isn't returning null in the Bulk API derived trigger context? (It will be null in future, batch and scheduled contexts) Can you see anything related to it under Administration Setup > Security Controls > Session Management?