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
Zen Newman 1Zen Newman 1 

Having trouble creating a create opportunity Visualforce page

Hello, fairly new to Visualforce. I'm trying to create a Visualforce page to replace the default create new opportunity page. The code I used came from a similar new account page which is working. I'm seeing no warrnings in the developer console and the page displays fine, but when I click the save button, no record is created and when I click the cancel button, it flags required fields as needing to be filled out to move forward. Can someone tell me where I'm going wrong? Thank you! 
 
<apex:page standardController="Opportunity" lightningStylesheets="TRUE" showHeader="TRUE" docType="html-5.0">
    <apex:SectionHeader title="New Opportunity"> 
    	<apex:form >
        	<apex:pageBlock title="Add Opportunity"  mode="edit">
          		<apex:pageBlockButtons >
            		<apex:commandButton action="{!save}" value="Save"/>
            		<apex:commandButton action="{!cancel}" value="Cancel" immediate="true"/>
       			</apex:pageBlockButtons> 
                <apex:pageBlockSection >
                    <apex:inputField value="{!Opportunity.Name}" />
                    <apex:inputField value="{!Opportunity.AccountId}" />
                    <apex:inputField value="{!Opportunity.Stagename}" /> 
                    <apex:inputField type="date" showDatePicker="TRUE" value="{!Opportunity.CloseDate}" required="TRUE" /> 
                    <apex:inputField type="date" showDatePicker="TRUE" value="{!Opportunity.Project_Launch_Date__c}" required="TRUE" /> 
                    <apex:inputField value="{!Opportunity.Broker_Account__c}" />
                    <apex:inputField value="{!Opportunity.Broker_Contact__c}" /> 
                </apex:pageBlockSection>
            </apex:pageBlock>
    	</apex:form>
    </apex:SectionHeader>
</apex:page>

Screenshot
Best Answer chosen by Zen Newman 1
AmarpreetAmarpreet
Hi,

Please try below Code:
 
<apex:page standardController="Opportunity" lightningStylesheets="TRUE" showHeader="TRUE" docType="html-5.0">
    <apex:SectionHeader title="New Opportunity"> 
    	<apex:form >
        	<apex:pageBlock title="Add Opportunity"  mode="edit">
          		<apex:pageBlockButtons >
            		<apex:commandButton action="{!save}" value="Save"/>
            		<apex:commandButton action="{!cancel}" value="Cancel" immediate="true"/>
       			</apex:pageBlockButtons> 
                <apex:pageBlockSection >
                    <apex:inputField value="{!Opportunity.Name}" />
                    <apex:inputField value="{!Opportunity.AccountId}" />
                    <apex:inputField value="{!Opportunity.Stagename}" /> 
                    <apex:inputField  showDatePicker="TRUE" value="{!Opportunity.CloseDate}" required="TRUE" /> 
                    <apex:inputField showDatePicker="TRUE" value="{!Opportunity.Project_Launch_Date__c}" required="TRUE" />
                    <apex:inputField value="{!Opportunity.Broker_Account__c}" />
                    <apex:inputField value="{!Opportunity.Broker_Contact__c}" />

                </apex:pageBlockSection>
            </apex:pageBlock>
    	</apex:form>
    </apex:SectionHeader>
</apex:page>

 

All Answers

AmarpreetAmarpreet
Hi,

Please try below Code:
 
<apex:page standardController="Opportunity" lightningStylesheets="TRUE" showHeader="TRUE" docType="html-5.0">
    <apex:SectionHeader title="New Opportunity"> 
    	<apex:form >
        	<apex:pageBlock title="Add Opportunity"  mode="edit">
          		<apex:pageBlockButtons >
            		<apex:commandButton action="{!save}" value="Save"/>
            		<apex:commandButton action="{!cancel}" value="Cancel" immediate="true"/>
       			</apex:pageBlockButtons> 
                <apex:pageBlockSection >
                    <apex:inputField value="{!Opportunity.Name}" />
                    <apex:inputField value="{!Opportunity.AccountId}" />
                    <apex:inputField value="{!Opportunity.Stagename}" /> 
                    <apex:inputField  showDatePicker="TRUE" value="{!Opportunity.CloseDate}" required="TRUE" /> 
                    <apex:inputField showDatePicker="TRUE" value="{!Opportunity.Project_Launch_Date__c}" required="TRUE" />
                    <apex:inputField value="{!Opportunity.Broker_Account__c}" />
                    <apex:inputField value="{!Opportunity.Broker_Contact__c}" />

                </apex:pageBlockSection>
            </apex:pageBlock>
    	</apex:form>
    </apex:SectionHeader>
</apex:page>

 
This was selected as the best answer
Zen Newman 1Zen Newman 1
Awesome, that did what I needed it to. Thank you!