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

Override New button with visualforce and set field values

Can I use visualforce to set default values on a standard page layout?  I want to set the Opportunity Name field to a default value when the "new" button is clicked (and before the "save" button is clicked).   I am not sure what the visualforce command should look like to accomplish this task.  Is this possible?  Does anyone have a code snippet they could share?
Right now you can't accomplish this and still keep your page layout control. You can however override the New Opportunity page  with your own visualforce page, and construct your layout using pageBlocks and inputFields.  Then you can use a controller extension to set the default field in your constructor. 

<apex:page standardController="opportunity" extensions="OppExt">
<apex:form >
  <apex:pageBlock title="Opportunity Edit" mode="edit">
    <apex:pageBlockButtons >
        <apex:commandButton value="Save" action="{!save}"/>
        <!-- more buttons here -->
    <apex:pageBlockSection title="Opportunity Information">
        <apex:inputField value="{!}"/>
        <!-- fill this section with all of the inputFields you want to display -->
    <!-- create more sections in this block -->

public class OppExt {

    public OppExt(ApexPages.StandardController controller) {
        Opportunity opp = (Opportunity) controller.getRecord(); = 'My Default Name';



Thankyou!!  That worked great!  (my first visualforce page...  I'm so exited!! :smileyhappy:)