I have a webservice class 'restExample' which first performs DML operations and then calls a future method 'createDocument()'. This method will create PDF document. One important point: Running user is a guest user with user license Guest License
restExample:
@RestResource(urlMapping='/restExample')
global class MyRestContextExample{
@HttpPost
global static void getPara () {
//performs DML operations on multiple salesforce objects.
simulate.createDocument();
//'simulate' is the class name and 'createDocument' is the future method.
}
Reason behind using future method is : createDocument()
will also perform a callout which will use records that gets updated in restExample
webservice class.
Future Class: simulate
public class simulate{
@future(callout=true)
public static void createDocument(){
// code that generates PDF document.
}
}
A PDF document is getting successfully generated but it is throwing error when opened.
Error in Adobe Reader
When I execute future method createDocument()
from anonymous window
in Developer Console
, PDF gets generated correctly and also able to open properly. Hence the code in createDocument()
method works correctly.
NOTE: I am aware of the fact that I am not providing lot of code in the question. Three Reasons for the this: 1) All the DML operations are happening correctly and future method gets called in a seperate context. 2)Future method IS INFACT creating PDF. 3) PDF generation is happening with managed class,I just call that class in future method and code in managed class is hidden ..
restExample
webservice OR the callout performed in future method.anonymous window
in Developer Console, I am assuming VF is working correctly.