+ Start a Discussion
AxxxVAxxxV 

Getting around Standard Controller Exception Handling


I have a VF page for a standard object that uses standard controller and a controller extension. When an invalid object Id is passed, or record is unavailable (deleted or due to permissions), the standard controller throws the "hard-error" and the error is displayed in the standard SFDC UI (with the sidebar and header). My application has a completely cusom UI and I do not want to be "thrown" into the standard SFDC UI in case of an error. I tried to trap the error in the extension controller class, but it looks like standard controller traps it first and does not allow me to put in place any custom error handling.

Any suggestions?

MG ConsultingMG Consulting
Did you ever figure out a workaround for this? I am facing the exact same issue. Thanks!
Message Edited by MG Consulting on 01-21-2009 07:05 PM
andresperezandresperez

Hi,

 

I have an idea....

 

Don't use a standardController and an extension. Use just a custom controller and get the data there. Then put the SOQL in a try-catch block.

MG ConsultingMG Consulting
That's definitely a viable work around in most cases. But, in my particular case my Visualforce page must be added to to a standard object's exisiting page layout. And, unfortunately, you can only add Visualforce pages that extend the object's standard controller...
andresperezandresperez

 

True, but there are always more than one way to skin a cat... :smileywink:

 

I had a similar issue before where I wanted to add a VisualForce page to the object's layouts, this is how I did it.

<apex:page standardController="Posting__c" extensions="TPResolved2">

and this was my controller:

public TPResolved2(ApexPages.StandardController controller) {
  postingID = controller.getID();
  Posting__c posting = [SELECT <Fields> FROM Posting__c WHERE id = :PostingID LIMIT 1];
}

Now, make sure the data you display is read from the extension and not from the standard controller.

Message Edited by andresperez on 01-21-2009 09:33 PM
AxxxVAxxxV

Did this solution work for anyone?

 

As far as I recall I had tried this. But if an invalid Id is passed to the page, the standard controller will throw an error before the

 

postingID = controller.getID();

 

statement is even reached and consequently, the hard error is thrown before you get a chance to trap it...

 

 

 

Message Edited by AxxxV on 02-16-2009 11:21 PM
MFrielMFriel

I just tried this solution and it does not work.  Does anyone have any other ideas for this?