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
tobibeertobibeer 

index page - differentiate url rewrite vs. home page vs. 404 error handling

I am using a single index page which I call dispatcher and which decides on what to do with any incomming call. It is using a StandardController for a custom object with a controller extension and dynamically binds templates. I have a rewriter class that maps any incomming url to a custom object, if found. All that works well. However, there are a few exeptions where I am not sure as to how to distinguish them in my controller extension from any redirected pages which are:

 

1) the index page being called as the home page

2) the index page being called as the 404 error handling page

 

So, here are my questions...

 

A) How can I detect in the controller extension for my unified startpage that it is being called as either the home page or via 404 error handling? ...the standard behaviour being implemented via /dispatcher?id=CustomObjectId.

 

B) How can I, alternatively, make my url rewriter 404 status aware, such that it not only redirects to some other url but also returns a 404 http status to the client?

 

Cheers, Tobias.

Best Answer chosen by Admin (Salesforce Developers) 
tobibeertobibeer

Ok, I don't know if this is the best solution, but I made it work as follows...

 

1) Site.getOriginalUrl() returns a non NULL value only for urls that go unmapped by the rewriter, hence returning a 404


2) stdController.getId() is NULL when the home page is called

 

  • also true for urls returning 404, yet Site.getOriginalUrl() is NULL when called via home page

3) stdController.getId() is set to a valid id for any url that the rewriter class successfully maps to a custom object record

 

If you know of any other solutions, please post them anyways as I am not sure at all that using Site.getOriginalUrl() will always return reliable results no matter what the circumstances.