function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
AshanAshan 

PageReference.getContent()

When i tried to run PageReference.getContent() method inside a trigger

PageReference pdf=Page.DsignationLetter; 
pdf.getParameters().put('id',employeeId);
body = pdf.getContent();

 

i get the following exception message.


Getting content from within triggers is currently not supported.

 

This works fine in normal apex classes.

 

So I tried to do this in a @Future method and called future method from the trigger.

Then i get some kind of a authentication problem. The content looks like this

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">





<script>
var escapedHash = '';
var url = 'https://login.salesforce.com/........; (this contains visualforce page name and object id)
if (window.location.hash) {
   escapedHash = '%23' + window.location.hash.slice(1);
}
if (window.location.replace){
window.location.replace(url + escapedHash);
} else {;
window.location.href = url + escapedHash;
}
</script>

</head>


</html>

When i try to browse the url, it takes me to the salesforce login page.

 

If anyone has an idea on this please help

Thanks

 

 



DrBixDrBix

I"m having the same problem and I "think" I know what's going wrong.  You were right, it is an authentication problem.  I think the issue is that the @future method doesn't have the "logged in context" to access the page, so what acutally comes up is the login page, not the page you were trying to load.  I haven't figured out a workaround yet other than not calling it in an @future method or not calling it in a Batched method.  Let me know if you figured something else out.