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 : 

1
2
3
4
5
<apex:page standardController="Zoom_Data__c" >
 <script>
      window.top.location.href = '/lightning/o/Zoom_Data__c/new?nooverride=1&defaultFieldValues=Name=Test';
  </script>
</apex:page>

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 : 
1
/lightning/o/Contact/new?defaultFieldValues=OwnerId={!Value}

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

To pass multiple value you can use below URL : 
1
/lightning/o/Contact/new?defaultFieldValues=OwnerId={!Value},AccountId={!Value}


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 !

Thanks
Keep Coding 

Post a Comment

0 Comments