I am attempting to override the "new" button that I see on the Opportunity List page with a Visual Force page. I intend to use the same page and same controller for the New and Edit buttons. The Edit functionality is working as expected. The "New" is throwing an error.
When I click on the "New" button, I am getting the following message.
An internal server error has occurred
An error has occurred while processing your request. The salesforce.com support team has been notified of the problem. If you believe you have additional information that may be of help in reproducing or correcting the error, please contact Salesforce Support. Please indicate the URL of the page you were requesting, any error id shown on this page as well as any other related information. We apologize for the inconvenience.
Thank you again for your patience and assistance. And thanks for using salesforce.com!
Error ID: 630716990-2384169 (-509331411)
I am reading the Visual Force in Practice Guide and it has the following text.
This can also occur when the StandardController instance is passed into an Apex custom controller extension as a parameter on the class constructor. If the record is retrieved by use of the getRecord() method on the StandardController instance, and some Apex code attempts to reference a field not bound on the page, an exception will be thrown.
I have bound all the fields. For the sake of conciseness, I have reduced the number of fields that are being added and displayed on the page. It is a mix of standard fields and custom fields.
Here is the code for my ControllerExtension.
public with sharing class OppExtension
{
private final Opportunity opportunity;
public Boolean showQuoteNowButton {get;set;}
public class PageValidateException extends Exception{}
// The extension constructor initializes the private member
// variable mysObject by using the getRecord method from the standard
// controller.
public OppExtension(ApexPages.StandardController stdController)
{
if( !Test.isRunningTest() )
{
stdController.addFields(new List<string>{'RecordType','StageName','AccountId','Name','CloseDate','Id','Contact__c','LeadSource'});
this.opportunity = (Opportunity)stdController.getRecord();
}
if(this.opportunity.Id == null)
{
this.opportunity.RecordTypeId = '012700000005nffAAA';
}
else
{
if(this.opportunity.X42Id__c == null){
showQuoteNowButton = true;
}
else
{
showQuoteNowButton = false;
}
}
}
}
Here is my Visual Force Page.
<apex:page standardController="Opportunity" extensions="OppExtension" showheader="true" sidebar="true">
<apex:pageMessages id="msgs" rendered="true" showDetail="true">
</apex:pageMessages>
<apex:sectionHeader title="Opportunity Edit" subtitle="{!Opportunity.name}"/>
<apex:form >
<apex:pageBlock title="Opportunity Edit" mode="edit">
<apex:pageBlockButtons location="bottom">
<apex:commandButton title="Quote now" value="Quote Now" action="{!save}" rendered="{!showQuoteNowButton}"/>
<apex:commandButton value="Cancel" action="{!cancel}"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Naming convention: Party Name-Branch Name-Site Location-Project Description" columns="1">
<apex:inputField value="{!Opportunity.Name}" required="true"/>
</apex:pageBlockSection>
<apex:pageBlockSection title="Opportunity Information" columns="2">
<apex:inputField value="{!Opportunity.Floors__c}" required="true"/>
<apex:inputField value="{!Opportunity.StageName}" required="true"/>
<apex:inputField value="{!Opportunity.AccountId}" required="true"/>
<apex:inputField value="{!Opportunity.CloseDate}" required="true"/>
<apex:inputField value="{!Opportunity.Contact__c}" required="true"/>
<apex:inputField value="{!Opportunity.LeadSource}" required="true"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
opportunity
variablefinal
?