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
jadentjadent 

Populating Field Values on New

I'm new to sfdc developing and i would like to pre-populate a field value when someone clicks the new button on any given object.

 

To my limited understanding there is no trigger that fires at this point. Is there a way to pre-populate field values using apex when someone clicks the new button? Thanks!

shillyershillyer

Two ideas:

 

1. Use Default Values when defining the field

2. Use a S-Control URL and override the button. You can pass field values in the URL, as discussed here

 

Hope that helps,

Sati

jadentjadent

Thanks for the ideas i'll give the s-control a try as default values are not powerful enough.

 

Although that reminded me of another question on formulas i had. Do you know if its possible to reference the Who object in a Cross-Object Formula (My post about it is below)? Thanks again

 

http://community.salesforce.com/sforce/board/message?board.id=custom_formula&thread.id=5002

 

JMPlayer22JMPlayer22

It depends on where your "New" button is too...

 

If you are wanting to pre-pop some values over to a new related list object (i.e. pre-populate some Account field values onto a new Opportunity related to the account), the way I usually do this is to "clone" the "New" button and then replace it with the pre-populating "New" button that I make...

 

First, go to your starting object (i.e. Account) and go down to the related list of the related object for which you want to make the new button (i.e. New Opportunity).  Click the default "New" button and then copy the URL from the address bar once the new record page is up. 

 

Next, create a new button on the related object (i.e. Custom Opportunity Buttons)and paste your URL into the section at the bottom (you can pick the with/without headers however you want...what matters is that it's a URL button).

 

You're going to want to change some things in your URL -

 

- find any instance of the parent record ID (ie account Id...the one that in this case starts "001") and replace it with the record ID merge field value (you can find/select this from the advanced formula dropdowns).  What you're doing is basically finding any place that SFDC has already set it up to prepopulate values and you're resetting it to the merge fields so that YOUR button will keep doing the same thing (leaving the record IDs in your formula is going to auto-populate the same exact record ID every time...and you don't want that)

 

- next, go back to your new record page that you opened when clicking the "New" button (new opportunity in edit mode) I'm not sure if ie8 does this or not, but in firefox/chrome if you highlight text on the page and then right-click and select "view selection source" or "inspect element".  Now you're going to look for the "label for=" and copy the weird looking id after "label for=". (in chrome, it should automatically take you right to the label for...just double click on it until it looks like it's in edit mode and then copy the id) (ie - the "Name" field label for Opportunity is "opp3"and custom fields will have a longer label for - you may need to highligh the field name and the open box to find the label for)

 

next, add &, the label for, =, and the default value you want from the parent object or hardcoded

 

ie. https://na6.salesforce.com/006/e?retURL={!Account.Id}&opp3={!Account.Name}&opp4={!Account.Name}&opp14=TEST

 

the example above (if saved into a URL button on Opportunities) would auto-pop the account name into the Opportunity name field and into the account field.  It would also populate "TEST" into the description on the Opportunity.

 

The last step is replacing the "New" button on your account page layout related list section...

 

Go to the account page layout and click edit...go to the Opportunity related list and select the wrench/settings..

 

uncheck the "new" button and then go to the buttons section and add your new button...and save the page layout 

 

That should work...you can always go back and change/add to what you want to prepop...and also you can remove the first part of the URL if you want to save space...using just this will work:

 

/006/e?retURL={!Account.Id}&opp3={!Account.Name}&opp4={!Account.Name}&opp14=TEST

 

 

 

pierpipierpi

Hi,

That is definitely an option; however, is it possible to achieve the same goal without passing the field values in the URL?

 

Thanks

Pierpi