Default Value for Standard Fields in Salesforce

 In this blog you will learn a workaround to set Default value for Standard Fields in Salesforce.

In below example I am having a Custom Object Zoom_Data__c and I will auto-populate Name field in it.

To implement the workaround please follow below steps : 

Step 1 : 

Create a Visualforce page as shown below : 

<apex:page standardController="Zoom_Data__c" >
 <script> = '/lightning/o/Zoom_Data__c/new?nooverride=1&defaultFieldValues=Name=Test';

In above VF page I am using a URL hack to pass the default value in the standard field. You can defaultFieldValue parameter in URL to pass the default value as shown in above example.

Step 2:

Override the new button of the Object with this Visualforce page : 

This will do the trick, now try to create a new record of the Object and you will be having default value there.

How to Pass default parameters ?

To pass a single value you can use below URL : 

You can bind variables in the URL or pass the String directly.

To pass multiple value you can use below URL : 

Checkout complete tutorial below  :

 If you have any question please leave a comment below.

If you would like to add something to this post please leave a comment below.
Share this blog with your friends if you find it helpful somehow !

Keep Coding 

Post a Comment


  1. How to pass something like this - defaultFieldValues=FieldName=id1,id2 ?
    Multiple values for same field.

    1. Hi Simran,

      What is the field type ?

    2. Hey,

      I'm trying to populate WhoId with multiple values. 'Shared Activities' is enabled for my org. Apparently we cant do it with apex, can we?

    3. Event - WhoId field - to populate with multiple contact ids selected in a list view.

    4. Simran, have you tried it by passing the list as the value ?

    5. Yes, I tried passing as list and using other separators as well but no luck so far. I reckon we can't pass more than one id in whoid field via apex and can only be done via UI.

    6. &defaultFieldValues=WhoId='+selectedContactsIDString;
      String of ids selected in list view separated by comma. I tried other separators and also a list instead of string.

    7. Seems like a limitation to set the default values ! I will do some more research on it and let you know.

  2. Hi Kapil, this is fantastic demonstration, thank you.
    My use case is a bit more complex - I need to override the new opportunity button, and the default value for the Opportunity currency need to be that of the Account.
    So I need to query the account object from which I'm creating the new opportunity. Is there a line of code I can add to your example above that will provide such solution?

    1. Yes, as it's a vf page which is sending the default parameters maybe you can add a apex class there and get the selected account based on the Id !