November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
This should be a safe way:
PageData pd;
PageReference pr = new PageReference(PageId);
if(!PageReference.IsNullOrEmpty(pr))
pd = DataFactory.Instance.GetPage(pr);
if (pd != null)
{
// Your page exists and you have access to it
}
Hi,
Thank you for your respond,
I think that new PageReference create a new PageReference even if the page dosent exist.
And that mean PageReference.IsNullOrEmpty is not going to be NullOrEmpty becase the Reference exist but is not a valid page.
if(PageReference.IsNullOrEmpty(pr))
return;
try
{
// I GOT A PAGE NOTFOUND exception here.
PageData pd = DataFactory.Instance.GetPage(pr);
pageList.Add(pd);
}
catch
{
}
There is one way to do it without the try catch, but I am not sure how supported it is.
you can use:
if(PageCoreData.Load(PageRef) != null)
{
//The pageRef is ok and exists.
}
PageCoreData.Load returns null if you have a page ref that leads to a page that does not exist instead of throwing an exception. I have not investigated it much though.. Like if it is slow /cached, ..., ... so might be some issues in some cases im sure.
Hi,
I just wounder, which is the best way to verify that a page really exist?
I dont want to use try catch, and catch the pagenotfound exception.
PageReference pr = new PageReference(PageId);
try
{
PageData pd = DataFactory.Instance.GetPage(pr);
}
catch
{
throw...
}