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 

Getting content from within triggers is currently not supported.

When I try to call PageReference.getContent() from a trigger, I get the following error.

 

Getting content from within triggers is currently not supported.

 

Do anyone have a solution for this?

myforcedotcommyforcedotcom

Can you elaborate what you are trying to do with the PageReference.getContetnt() ?

JPClark3JPClark3

You may need to call out to an async (@future) method to getContent. Some features aren't allowed in triggers because they can require too much time during the transaction.

AshanAshan

PageReference pdf=Page.DsignationLetter;

pdf.getParameters().put('id',employeeId);

Blob body;

body = pdf.getContent();

AshanAshan

@JPClark3

I tried to do it in a @future method. But then the page is not rendred properly. When i looked at the content there is a url which directs to the page, but it needs to log again to salesforce

myforcedotcommyforcedotcom

When you fire a trigger your in the process of commiting the data and the page is out of reference. The same thing applies for @future methods.

 

Keep in mind triggers could be processing up to 200 records at a time so you cannot redirect either.

 

Are you firing off this process from a click on a VF page? If you are, use an extension class to handle this function.