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
arun kumar.ax887arun kumar.ax887 

How to set Default values to Standard Fields



     I have a requirement where in the default values have to be set for the Standard Field of Opportunity i.e. Opportunity Name, could any one suggest a solution for this. 



Thanks & Regards





Most likely a New button override.  Are you defaulting to the account name? If so you could create a button for the Opportunity related list on the account page layout.  I will assume that you want to default to "<Account Name> - " for the opportunity.


First, go to an account and click the New Opportunity button.Note the URL.  In my developer environment it is:


Now, in your browser, click View > Page Source.  Search for "Opportunity Name" and find the ID associated with the Opportunity Name.  In my environment it is "opp3"


Now go to Setup > Customize > Opportunities > Buttons and Links anc create a new button. Name it New Opportunity, make it a List Button and set behavior to open in existing window without sidebar or header.


copy every thing from you link above after in to the formula:



In this url, the retURL is the account id as well as the accid, so we need to replace those



Finally, you need to populate the Opportunity Name field: opp3

/006/e?retURL=%2F{!Account.Id}&accid={!Account.Id}&opp3={!Account.Name}+" - "


Now add this button to the account page layout on the related list for the opportunity (don't forget to remove the old one) and when you create an opportunity it will default to the account name.


Additionally you may want to add a validation rule that the Opportunity name is not equal to "<Account Name> - " which will make the users update the name.



I was successfully able to create a List Button that appears on the Account page layout in the Opportunity related list so when a user clicks "New Opportunity" the Opportunity Name field has a default value.


However, I want this default value to appear whenever the user creates a new Opportunity (i.e. also from the Opportunity tab when they click "New" button). Any suggestions how to do this? Seems like I need to create a Visualforce page - is that right??




That is correct, you will need to build a visualforce page.

Marc C.Marc C.

Thanks for this tip Kyle!

How can we do it in lightning?
Rick Matusiewicz 10Rick Matusiewicz 10
In a LWC you can create a map of your default field names to their values. This could be done using something like the following but with whatever fields you need:
import { encodeDefaultFieldValues } from 'lightning/pageReferenceUtils'

 const defaultValues = encodeDefaultFieldValues({
               AccountId:            this.accId,
               RecordTypeId:         this.recordTypeId,
               StageName:            this.OPPORTUNITY_STAGE_BUSINESS_QUALIFICATION

If working on a pure LWC (no Aura or VF composition) then you can use:

import { NavigationMixin } from 'lightning/navigation';

export default class MyClass extends NavigationMixin(LightningElement){

        type: 'standard__objectPage',
        attributes: {
            objectApiName: 'Opportunity',
            actionName: 'new'
        state: {
            defaultFieldValues: defaultValues

If you are working on a Lightning Out app, ie VF/Aura composition (VF -> Aura -> LWC) then you can pass your default field value map from the LWC to the parent Aura component via a CustomEvent:

navigateNewOppPage(defaultValues) {
    let navigateEvent = new CustomEvent('navigatecreateopp',{
        detail: {
            defaultfieldvalues: defaultValues

In Aura you can handle the CustomEvent and then call the recordCreate API:

    handleNavigateEvent : function(component, event, helper) {
        let createRecordEvent = $A.get("e.force:createRecord");
        let eventDefaultKeyValues = event.getParam("defaultfieldvalues").split(',');
        var defaultFieldValues = {};
            var key = String(pair.split('=')[0]);
            var value = decodeURIComponent((String(pair.split('=')[1])));
            defaultFieldValues[key] = value;

            "entityApiName": "Opportunity",
            'recordTypeId' : defaultFieldValues.RecordTypeId,
            "defaultFieldValues": defaultFieldValues,
This will open the standard record create page with all of your values defaulted.