+ Start a Discussion
Morgan MarcheseMorgan Marchese 

VF Page to Intercept New Case button and present Error if Account Billing Status = Cancelled

Hi All,

We want to override the New Case button with a VF Page that does a check if the account is cancelled or not via a picklist called "Billing Status" on the account object.

If Billing Status == 'Cancelled' we want to hit them with an error message that says they can't create a case for this account, but if Billing Status != 'Cancelled' then we want to proceed to the normal case record type selection/creation pages.

We have written the VF page below, and overwritten the standard button functionality, but when we click on the New Case button it asks us to select record type, and when we select it, it just loops back around and asks us to select record type again. When we select record type the second time and press 'continue', it lets us through to the new case page. We're never presented with the error page, even though the account is cancelled... what are we doing wrong?

VF Page:
<apex:page standardController="Account"
    IF(Account.Billing_Status__c == "Cancelled", 
       URLFOR($Page.CasePageMessenger, Account.Id,[id=Account.Id],FALSE),
       URLFOR($Action.Case.NewCase, Account.Id,[retURL="/001"], TRUE)
<apex:pageMessage severity="ERROR" 
    title="Case Create" 
    summary="This Account is cancelled and can not receive support.">