+ Start a Discussion
DataSpark AnalyticsDataSpark Analytics 

Auto populate fields with default values on New record page

On a custom object, I've managed to auto populate the custom object's name field to a default value using below custom apex page code:
<apex:page standardController="CustomObject__c"
    action="{!URLFOR($Action.CustomObject__c.New, null, ['Name'='Default Value'], true)}"  
/>
Now in addition to the Name field I also want to auto populate a Master-Detail field on the Custom object but it's not working. My code:
<apex:page standardController="CustomObject__c"
    action="{!URLFOR($Action.CustomObject__c.New, null, ['Name'='Default Value', Master-Detail__c='Default Value'], true)}"  
/>

I have been struggling to find reference to the proper syntax. I also have been wondering how does one view all the apex codes created for a custom object, as a starting point to learn the apex coding language.
Neetu_BansalNeetu_Bansal
Hi,

To auto populate fields on button click, you don't need to create a visualforce page, you can just put the values in the url and its all done. Please follow the following steps:
Let's suppose you want to populate Contact Name and Account Id of Contact by clicking a button on Account:
  • Create a custom button on Account, which opens a url.
  • You need to get the id of the name and Account field on Contact layout, by right click and click inspect element, you will get a unique id, lets suppose ids for Name is 00N21000000NleY and for account is CF00N21000000NlZE_lkid, CF00N21000000NlZE.
  • Use this url /003/e?00N21000000NleY=NeetuBansal&CF00N21000000NlZE_lkid={!Account.Id}&CF00N21000000NlZE={!Account.Name}&retURL={!Account.Id}
  • This will auto populate the values.
Let me know, if you need any other help.

Thanks,
Neetu
DataSpark AnalyticsDataSpark Analytics
Thanks, and managed to get the custom button created. When a person goes to the custom tab, under the Recent list view, how do I remove the standard New button and replace it with my custom button?
Neetu_BansalNeetu_Bansal
Hi,

Check this link:
https://help.salesforce.com/HTViewSolution?id=000182076&language=en_US (https://help.salesforce.com/HTViewSolution?id=000182076&language=en_US)

Thanks,
Neetu
黃至信 Reggie Huang黃至信 Reggie Huang
Hi Neetu,

The solution you post above is useful.
Can you give any document or link with more detail?

Thanks,
Reggie.

 
abhik dey 1abhik dey 1
How to use this in lightning experience? The above url hacks doesn't work in lighning 
Vijayakumar S 6Vijayakumar S 6
Populate the default values without pass the data from URL using apex. 
How to populate default values in new contact?