+ Start a Discussion
Brianna BollettieriBrianna Bollettieri 

Visualforce Pages - Making it record type specific and changing the way the page looks

I created a VF page and am using it in place of the standard opportunity screen. I currently am having two issues with it.

1. We have many different record types but I only want this visualforce page to apply to 2 of them.
2. Once I create a new record or enter an existing. The record always looks like it is on the edit page.

Any assistance would be greatly appreciated!
VineetKumarVineetKumar
What I would suggest you, is to override the New button to a custom VF page.
This VF page would be different from your existing form page. This page will control the redirection of your page to required page.
While you override, select the option of choosing the record type, which will be appended to the URL.
When you click next, the control will go to your VF page, here you can get the recordtype from the URL, using ApexPages.CurrentPage.getParameters().get(<urlparamname>);
Then in the controller you can make the controlled redirect.

Let me know if that helped.
Brianna BollettieriBrianna Bollettieri
Hi Vineet,

Thank you for your response. I already overrode the New, Edit, and View buttons with my VF page. I keep getting an error when I try to create a record saying "Formula Expression is required on the action attributes."

This is my controller:

<apex:page >
public with sharing class opportunityRedirect {

private ApexPages.StandardController controller;
public String retURL {get; set;}
public String saveNewURL {get; set;}
public String rType {get; set;}

public opportunityRedirect(ApexPages.StandardController controller) {

          this.controller = controller;

          retURL = ApexPages.currentpage().getParameters().get('retURL');
          rType = ApexPages.currentPage().getParameters().get('Intl Test');

}

public PageReference redirect(); {

          PageReference returnURL;

          // Redirect if Record Type corresponds to custom VisualForce page

          IF(rType == 'Intl Test') {

                     returnURL = new PageReference('/apex/International_Opportunities');

}

}
</apex:page>

And the beginning of my VF page is 

<apex:page standardController="Opportunity" extensions="OpportunityRedirect" action="{redirect}" >

I'm assuming the problem is within my controller but I'm not sure where.
VineetKumarVineetKumar
you are missing an exlamation mark in the formulae expression
<apex:page standardController="Opportunity" extensions="OpportunityRedirect" action="{!redirect}" >
Refer the above code.

Do mark my answer as best answer if it helped you
Brianna BollettieriBrianna Bollettieri
With the exlamation mark I get the following error and it won't allow me to save: Error: Unknown method 'OpportunityStandardController.redirect()'
VineetKumarVineetKumar
There is a mistake in your controller as well, I'm wondering how it got saved.
there is a semicolon in the class name, perhaps would have been a copy pasting error.. :)
Anyways :
Correct 
public PageReference redirect();{
To
public PageReference redirect(){


 
Brianna BollettieriBrianna Bollettieri
I must of copy and pasted it in here wrong, sorry! In my controller the semicolon isn't in there. I'm still getting the same error in my VF page when I try to save action="{!redirect}".
VineetKumarVineetKumar
can you remove this line and try 
private ApexPages.StandardController controller; and this.controller = controller;
These are not required.
Brianna BollettieriBrianna Bollettieri
I removed them both but it still won't let me add the exlamation mark in the first line of my VF page. And I am still getting the same error when I try to create a record  "Formula Expression is required on the action attributes."
VineetKumarVineetKumar
for formulae expression error you need to write like this
action="{!redirect}"
can you post me the page and controller seperately.
Please paste using <> on this editor tab
Brianna BollettieriBrianna Bollettieri
It won't allow me to save the below with the exlamation point. I get an error. It only allows me to save it without the exlamation point (as shown in the VF page below).
<apex:page standardController="Opportunity" extensions="OpportunityRedirect" action="{!redirect}" >
This is the controller.
<apex:page >
public with sharing class opportunityRedirect {

public String retURL {get; set;}
public String saveNewURL {get; set;}
public String rType {get; set;}

public opportunityRedirect(ApexPages.StandardController controller) {

       
       retURL = ApexPages.currentpage().getParameters().get('retURL');
       rType = ApexPages.currentPage().getParameters().get('Intl Test');

}

public PageReference redirect() {

       PageReference returnURL;
       
       // Redirect if Record Type corresponds to custom VisualForce page
       
       IF(rType == 'Intl Test') {
       
              returnURL = new PageReference('/apex/International_Opportunities');

}

}
</apex:page>

This is the VF page.
<apex:page standardController="Opportunity" extensions="OpportunityRedirect" action="{redirect}" >
<apex:pageMessages />
  <apex:form >
    <apex:pageBlock title="Opportunity" mode="edit">
        <apex:pageBlockButtons >
          <apex:commandButton action="{!save}" value="Save"/> <apex:commandButton action="{!cancel}" value="Cancel" immediate="true"/> <apex:commandButton value="edit" action="{!Edit}" immediate="true"/>
        </apex:pageBlockButtons>
      <apex:pageBlockSection title="Stage">
          <apex:repeat value="{!$ObjectType.Opportunity.fieldsets.stageFieldSet}" var="fieldValue">
              <apex:inputField value="{!Opportunity[fieldValue]}" />
          </apex:repeat>
        </apex:pageBlockSection>
      <apex:pageBlockSection title="Opportunity">
          <apex:repeat value="{!$ObjectType.Opportunity.fieldsets.opportunityFieldSet}" var="fieldValue">
              <apex:inputField value="{!Opportunity[fieldValue]}" />
          </apex:repeat>
        </apex:pageBlockSection>
        <apex:pageBlockSection title="Needs & Requirements">             
            <apex:repeat value="{!$ObjectType.Opportunity.fieldsets.nrFieldSet}" var="fieldValue"> 
                <apex:inputField value="{!Opportunity[fieldValue]}" rendered="{!!(ISBLANK(Opportunity.StageName) || Opportunity.StageName='Opportunity' )}" />
                <apex:outputField value="{!Opportunity[fieldValue]}" rendered="{!ISBLANK(Opportunity.StageName) || Opportunity.StageName='Opportunity'}" />
          </apex:repeat>
        </apex:pageBlockSection>
        <apex:pageBlockSection title="Proposal & Sell">
            <apex:repeat value="{!$ObjectType.Opportunity.fieldsets.psFieldSet}" var="fieldValue">
                <apex:inputField value="{!Opportunity[fieldValue]}" rendered="{!!(ISBLANK(Opportunity.StageName) || Opportunity.StageName='Opportunity' || Opportunity.StageName='Needs & Requirements' )}" />
                <apex:outputField value="{!Opportunity[fieldValue]}" rendered="{!ISBLANK(Opportunity.StageName) || Opportunity.StageName='Opportunity' || Opportunity.StageName='Needs & Requirements'}" />
            </apex:repeat>
        </apex:pageBlockSection>
        <apex:pageBlockSection title="Closed Won || Closed Lost">
            <apex:repeat value="{!$ObjectType.Opportunity.fieldsets.cwclFieldSet}" var="fieldValue">
                <apex:inputField value="{!Opportunity[fieldValue]}" rendered="{!!(ISBLANK(Opportunity.StageName) || Opportunity.StageName='Opportunity' || Opportunity.StageName='Needs & Requirements' || Opportunity.StageName='Proposal & Sell' )}" />
                <apex:outputField value="{!Opportunity[fieldValue]}" rendered="{!ISBLANK(Opportunity.StageName) || Opportunity.StageName='Opportunity' || Opportunity.StageName='Needs & Requirements' || Opportunity.StageName='Proposal & Sell'}" />
            </apex:repeat>
          </apex:pageBlockSection>
      </apex:pageblock>
    </apex:form>
</apex:page>


 
VineetKumarVineetKumar
In the controller you do not include the <apex:page> tags.
Were you able save the controller? :-|
Controller should be like this
public with sharing class opportunityRedirect {

    public String retURL {get; set;}
    public String saveNewURL {get; set;}
    public String rType {get; set;}

    public opportunityRedirect(ApexPages.StandardController controller) {       
        retURL = ApexPages.currentpage().getParameters().get('retURL');
        rType = ApexPages.currentPage().getParameters().get('Intl Test');
    }

    public PageReference redirect() {
        PageReference returnURL;
        // Redirect if Record Type corresponds to custom VisualForce page       
        IF(rType == 'Intl Test') {       
              returnURL = new PageReference('/apex/International_Opportunities');
        }
    }
}
VineetKumarVineetKumar
Also I can see in the page you have uses double !! for formula expression
Do correct that as well formula expression are always like {!____ }
Brianna BollettieriBrianna Bollettieri
I'm not sure what you mean by doubles? And I know they are supposed to have exlamation marks but as I mentioned previously it will not allow me to save it with the exclamation mark...
VineetKumarVineetKumar
Even after making changes to the extension class?
Brianna BollettieriBrianna Bollettieri
Yes
VineetKumarVineetKumar
can you share screen your credentials or your screen?
skype : vineet_kumar1988
Brianna BollettieriBrianna Bollettieri
I have lync and when I searched for your username it said there were no matches
VineetKumarVineetKumar
I'm not on lync, give me your Id