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
believebelieve 

Invoke visualforce page in Apex?

Anyone knows how to invoke a visualforce page in Apex code without using callout (which requires you to setup the remote site)? Essentially I just want to make a 'local' http request.

kiranmutturukiranmutturu

do u want to invoke the vf page with in the same organization then u can do like this

 

pagareference pf = page.vfpagename;

florianhoehnflorianhoehn

Hi believe,

 

I guess you want the content of a vf page. This can be done with a pageReference method 'getContent'

 

PageReference pR = Page.ExamplePage;
Blob content = pR.getContent(); 

There are some limitations around the 'getContent' method so have a look if you can achieve what you need: SF PageReference Documentation

 

Hope this helps!

 

Florian

believebelieve

Thanks for the reply. Unfortunately this is not allowed in Apex batch (which is what I really need).

craigmhcraigmh

What do you need from it? You can parse out what you need if you query for the ApexPage in SOQL.

believebelieve

What I want is to reuse the logic (formatting) in the visualforce page in Apex batch class. The visualforce page returns an excel file (or really html) so it builds all the cells with width, color etc. I want to store the same content in a file but in Apex batch. And I am try to avoid replicate all that code.