You need to sign in to do that
Don't have an account?
mustapha L 1
ApexCode to open VisualForce Page
Hi all,
looking for Apex syntax how to open a VisualForce page
ie :
if (field==Case1)
{open visualForce1}
if (field==Case2)
{open visualForce2}
Many thaks for your assistance.
looking for Apex syntax how to open a VisualForce page
ie :
if (field==Case1)
{open visualForce1}
if (field==Case2)
{open visualForce2}
Many thaks for your assistance.
try below code:
public pagereference Redirect()
{
if (field==Case1)
{
PageReference vfPage1 = new PageReference('/apex/visualForce1');
vfPage1.setRedirect(true);
return vfPage1;
}
if (field==Case2)
{
PageReference vfPage2 = new PageReference('/apex/visualForce2');
vfPage2.setRedirect(true);
return vfPage2;
}
return null;
}
Thanks,
Gaurav
All Answers
try below code:
public pagereference Redirect()
{
if (field==Case1)
{
PageReference vfPage1 = new PageReference('/apex/visualForce1');
vfPage1.setRedirect(true);
return vfPage1;
}
if (field==Case2)
{
PageReference vfPage2 = new PageReference('/apex/visualForce2');
vfPage2.setRedirect(true);
return vfPage2;
}
return null;
}
Thanks,
Gaurav
Hi,
You can try this code also
Feel free to ask if you have any question.Thanks,
799 Coder
I have added the following to extract my Quote ID (the button is into Quote Layout)
Id MyId= ApexPages.currentPage().getParameters().get('id'); //this looks OK
however i do not have syntax how to insert this MyId into PageReference.
PageReference vfPage1 = new PageReference('/apex/visualForce1/MyId'); //of course doesn't work
or
pg = Page.YOUR_PAGE2.myId; //doesn't work neither
could you just help me on this particular point ?
Many thanks
Adjusted code to pass the parameter into url.
Code Sample 1:
// Method to redirect to vf page and passing the parameter
public pagereference Redirect()
{
PageReference vfPage = null;
if (field==Case1)
{
vfPage = new PageReference('/apex/visualForce1?qID='+quoteID);
}
if (field==Case2)
{
vfPage = new PageReference('/apex/visualForce2?qID='+quoteID);
}
vfPage.setRedirect(true);
return vfPage;
}
Code Sample 2:
// statement to get the parameter
quoteID = Apexpages.currentPage().getParameters().get('qID');
Thanks,
Gaurav
PageReference vfPage1 = new PageReference('/apex/visualForce1/?id=' +MyId)
this fix the issue how to pass the ID but doesn't work as expected for 2 reasons:
1) I do not kno reason but the "VisualForce1" is duplicated into opened page
in fact when i press button i have something like
/apex/VisualForce1/VisualForce1/id=value_of_id
2) second, it looks like the returned ID is not the expected one, what causng error.
it is suppoed to return the Quote ID (what works well when the Button is directly linked to the VisualForce1...but not since going trhought REdirect
i do not undesrtand why same command line could provide not same result:
this works well on "VisualForce1 extension"
Id MyId= ApexPages.currentPage().getParameters().get('id');
many thans for all assistance.
unexpected "/" just before parameter.
PageReference vfPage1 = new PageReference('/apex/visualForce1 / ?id=' +MyId)
HUGE thanks to you both.
I am trying to do the same thing to open a vf page from apex class:
public pageReference returnpage(){
system.debug('in pdfPageClass///');
PageReference vfPage1 = new PageReference('/apex/pdfPage');
vfPage1.setRedirect(true);
return vfPage1;
}
and calling this method from another class, but when this runs, the vf age does not open.
Can someone pls help.
Thanks,
Namrata