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
JHoskinsJHoskins 

Visualforce & Native Page Layouts - Together?

I'm in desperate need of development advice as it relates to Visualforce before the Holiday and I was wondering if you could point me in the right direction.
Any advice, code examples or links to references would be greatly appreciated.

I need to know if its possible to use Visualforce & Native Page Layouts together within One Object (Case) with a single Record Type.

Scenario:
We have one Record Type "Accounting" for Cases with multiple case reasons, "Check Image Request",  "Inbound Repricing" & "Provider Login Request"

We need a way to use Visualforce for specific Case Reasons.
So Case Reason "Check Image Request" uses the native Case Page Layout but Case Reason "Provider Login Request" uses a Visualforce Page.

I've tried overriding the "View" Action under Button & Links to a Visualforce Page with an extended Controller that overwrites the view() method. But for some reason It's not executing my code.

Code:
public class caseExtendedController {
    private final Case c;
    public caseExtendedController(
ApexPages.StandardController stdController) {
        this.c = (Case)stdController.getRecord();
    }
    public PageReference view() {
       if(c.reason == 'Provider Login Request'){
               System.debug('Hi');
             return new PageReference('http://www.google.com');
        }else{
               return new ApexPages.StandardController(c).view();
        }
    }
}
 
My example above is trying to return a specific reference based on case reason.
/{!case.id}  for native page layout or /apex/vfPage?id={!case.if} for a Visualforce Page designed for a specific case type.

I noticed if I override "View" with a Visualforce Page all links like /{!case.id} automatically redirect to /vforcePage?id={!case.id}
So I'm not sure If I should use Override under buttons & link.


The Page Layout for Case Reason "Provider Login Request" is below:
Notice I'm only rendering the form if Case Reason Matches "Provider Login Request"

The Ultimate Question: Would it be wise to just use do conditional displays for all Case Reasons?

Code:
<apex:page standardController="Case" extensions="caseExtendedController">
  <!-- Define Tab panel .css styles -->
  <style>
    .activeTab {background-color: #236FBD; color:white; background-image:none}
    .inactiveTab { background-color: lightgrey; color:black; background-image:none}
</style>
  <!-- Create Tab panel -->
  <apex:form rendered="{!if(case.reason='Provider Login Request','true','false')}">
    <apex:pageBlock title="Case # {!case.CaseNumber} - {!case.Reason} ({!case.Match_Result__c})" mode="edit">
      <apex:pageBlockButtons location="top">
        <apex:commandButton action="{!Save}" value="Save"/>
        <apex:commandButton action="{CloseCase}" value="Close Case"/>
      </apex:pageBlockButtons>
      <apex:pageBlockSection columns="2" title="Information from Webform to work this Case">
        <apex:outputField value="{!case.SuppliedFirstName__c}"/>
        <apex:outputField value="{!case.Organization_Type__c}"/>
        <apex:outputField value="{!case.SuppliedLastName__c}"/>
        <apex:outputField value="{!case.SuppliedCompany}"/>
        <apex:outputField value="{!case.SuppliedEmail}"/>
        <apex:outputField value="{!case.SuppliedPhone}"/>
        <apex:outputField value="{!case.Match_Result__c}"/>
      </apex:pageBlockSection>
      <apex:pageBlockSection columns="2" title="Please MATCH the credentials to a current Provider Account">
        <apex:inputField value="{!case.FEIN__c}"/>
        <apex:inputField value="{!case.NPI__c}"/>
        <apex:inputField value="{!case.NABP__c}" rendered="{!CONTAINS('Pharmacy',case.Organization_Type__c)}"/>
        <apex:inputField value="{!case.DEA__c}" rendered="{!CONTAINS('Physician',case.Organization_Type__c)}"/>
        <apex:inputField value="{!case.DPR__c}" rendered="{!CONTAINS('Physician',case.Organization_Type__c)}"/>
      </apex:pageBlockSection>
      <apex:pageBlockSection columns="2" title="Requested User Login Information">
        <apex:inputField value="{!case.SuppliedUsername__c}"/>
        <apex:inputField value="{!case.accountId}"/>
        <apex:inputField value="{!case.SuppliedPassword__c}"/>
        <apex:outputField value="{!case.contactId}"/>
      </apex:pageBlockSection>
    </apex:pageBlock>
  </apex:form>

</apex:page>
 
I'm thinking as an absolute last resort I could a use Java Script to redirect on page load but there has to be something I can to with Apex Code.

I know its Christmas Eve but I don't know where else to turn.

Thanks & Happy Holidays
Best Answer chosen by Admin (Salesforce Developers) 
dchasmandchasman
You are close - what you need to leverage for this type of conditional routing is <apex:page action> - your view() method is not going to get called automatically (first time I have seen this assumption made but actually seems like a very reasonable mental model). Something like this should get you where you want to go:

Code:
public class caseExtendedController {
public caseExtendedController(ApexPages.StandardController controller) {
}

public PageReference route() {  return c.reason == 'Provider Login Request' ? new PageReference('http://www.google.com') : null;
}
}

<apex:page standardController="Case" extensions="caseExtendedController" action="{!route}">
...
</apex:page>

There are a number of related threads in this forum - if you search on Conditional Routing you'll find a few that should be helpful, e.g. this one



Message Edited by dchasman on 12-29-2008 09:55 AM