0

I have a link on an object that contains code similar to the following.

var VFBase = "/apex/MyVFPageName_"; 
var DBFld = "{!MyObject__c.MyField__c}"; 
var Suff = "?id={!MyObject__c.Id}"; 
var VFFull = VFBase.concat(DBFld); 
var VFFull = VFFull.concat(Suff); 
window.open(VFFull); 

So it creates a VF Page name based on a field value on my object that will be something like...

/apex/MyVFPageName_A?id={!MyObject__c.Id}

or 

/apex/MyVFPageName_B?id={!MyObject__c.Id}

What I want to be able to do is before the window.open is test for the existence of the VF Page.

So if /apex/MyVFPageName_A or /apex/MyVFPageName_B does not exist then I want to instead open a page called /apex/MyVFPageName (which I know will for sure exist)

What I need to know is how I can check for the existence of a given VF page before I attempt to open it.

Any assistance would be greatly appreciated.

1

If you want to be certain about visualforce page you can query for that page using javascript API at run time with following code.

{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")} 
result = sforce.connection.query("Select id,Name from apexpage where name='MYVFPAGENAME'");

records = result.getArray("records");
if(records.length)
{
 //page found write your logic here.
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.