You need to sign in to do that
Don't have an account?
dbelwood
Calling PageReference.getContent().toString() not seeing recently inserted data
Hi All,
Quick question, though I think I know the answer. I've got a quite complex apex method running as a result of being called from a VF command button. During this method I insert and update several records. At the end I am trying to generate html and plain text representations of VF pages to persist to an SObject that can then be picked up by a custom C# app and posted via SMTP. This seems relatively straightforward, but I'm guessing that PageReference.getContent() runs in a separate execution context, so won't have access to data inserted in another context.
Question 1, if I call PageReference.getContent() from within an Apex method, does it run in a separate context and thus not have access to the DML changes in the current context?
Question 2, if 1 is true, is there any way to accomplish this? I've tried persisting SObject-based parameters, but this is just the same thing as above, really.
Hope this makes sense and appreciate any help anyone can offer.
Best regards,
Dan
Quick question, though I think I know the answer. I've got a quite complex apex method running as a result of being called from a VF command button. During this method I insert and update several records. At the end I am trying to generate html and plain text representations of VF pages to persist to an SObject that can then be picked up by a custom C# app and posted via SMTP. This seems relatively straightforward, but I'm guessing that PageReference.getContent() runs in a separate execution context, so won't have access to data inserted in another context.
Question 1, if I call PageReference.getContent() from within an Apex method, does it run in a separate context and thus not have access to the DML changes in the current context?
Question 2, if 1 is true, is there any way to accomplish this? I've tried persisting SObject-based parameters, but this is just the same thing as above, really.
Hope this makes sense and appreciate any help anyone can offer.
Best regards,
Dan
The DML changes commit at the end of the request (your action method) , since you are not yet at the end i believe the call to getContent() will not see the uncommitted DML.
Question 2, if 1 is true, is there any way to accomplish this? I've tried persisting SObject-based parameters, but this is just the same thing as above, really.
I think you can use @future to perform this. Your action method would do the DML, then call an @future method and return.
The @future method would run and see the changed data when calling getContent().
Thanks for the quick reply. I've previously made a separate @future method to do just such a thing, but received the highly cryptic error - "Inline content was null" error in the output Visualforce and switched back. Have you seen this error before, if I could track down what this refers to, I'd have a better chance of successfully using the @future strategy.
Many thanks,
Dan
i have not seen that error.
Thanks for the help, I'm beginning to think that one can't produce VF content as a string from a @future method. I tried a very simple test:
Code:
results in;
<h3><em>Exception: null in inline content TestPattern</em></h3>
Perplexing...
Dan
I am thinking about a solution that will work for you now.
Message Edited by dchasman on 01-08-2009 02:59 PM
Its not possible to to use these methods from a @Future Method
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_annotation_future.htm
or the following.
• Triggers
• Scheduled Apex
• Batch jobs
• Test methods
• Apex email services