Auto Populate fields while creating a new record in Salesforce
11:17 AM
Whenever a user creates a new Account, Contact, Opportunity or any custom object record it is sometimes required to automatically populate certain fields with values.
You could do this by setting the "default" value on a text field. However, there are number of restrictions. One workaround would be to use Workflow rules for field updates, but remember workflow rules are fired only after you hit the "Save" button
Let's say that you would want the default value of the "Billing Country" field on Account to be set to "India". The video below shows how to do this by passing values through the URL.
P.S: This is not a best practice, but just in case it might help in some situations. You could override the "New" button and pass parameters through the URL.
You could do this by setting the "default" value on a text field. However, there are number of restrictions. One workaround would be to use Workflow rules for field updates, but remember workflow rules are fired only after you hit the "Save" button
Let's say that you would want the default value of the "Billing Country" field on Account to be set to "India". The video below shows how to do this by passing values through the URL.
P.S: This is not a best practice, but just in case it might help in some situations. You could override the "New" button and pass parameters through the URL.
6 comments
Cool idea...
ReplyDeleteOne question: I guess I need to write a VF page to override the New button and have this page redirect to the standard detail page for the Object, with the parameter embedded in the URL.
Is this right?
How do I find the detail page URL?
Thanks
Hello.. the general URL pattern is "https://yourinstance.salesforce.com/keyprefix/e?retURL=something&someotherparameter=somevale"
DeleteYou could use the Describe call to find out the key prefix of the object. Else, you could just hardcode it even though it's not a best practice.. I believe key prefix does not change for the lifetime of ur license..
Here is a sample URL for Account object, 001 is the keyprefix for Account.
https://na5.salesforce.com/001/e?retURL=/001/o ... Now,after you add values the URL changes to
https://na5.salesforce.com/001/e?accname=test&retURL=/001/o
This is very helpful
ReplyDeleteWould it also work for the new button located on a related list?
How can I access the parent object in my override page? I need to fill some fields based on values from the parent object.
Many thanks
I am not sure if you could get the parent ID from the standard page layout. You could do it from a visualforce page by replicating the standard layout and the "New" button in your related list would redirect to the child object's standard page layout with values passed through the URL. Hope that helps.
DeleteHey the NEW button in child page means , the NEW button in child TAB or Object. You need to override that with what has been discussed earlier. This works the same way.
DeleteFor ex. Contact is present under Account. You go SETUP--> Customize-->Contact-->Buttons-->NEW
do a override with
https://yourinstance.salesforce.com/keyprefix/e?retURL=something&someotherparameter=somevale
then go back to an account record , click on NEW button present in contact related list. You can see the change. Hope it helps :)
Correct. As Bibhu explained you can always override buttons.
ReplyDelete