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); 

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




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 Answer 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.

result = sforce.connection.query("Select id,Name from apexpage where name='MYVFPAGENAME'");

records = result.getArray("records");
 //page found write your logic here.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .