Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

Is there a way to pre-populate some of the fields on a standard layout page for an object (standard or custom)? For example, if you click on the "New Opportunity" button in the Opportunity related list on the Account page, it will be directed to the new "Oppurtunity Edit" page.

enter image description here

Notice, that the "Test Account" value in the "Account Name" field is pre-populated. Salesforce does that for you. I want to pre-populate the "Amount" field value on that page when the user arrives on this page by clicking the "New Opportunity" button. How do I go about doing this?

Anup

share|improve this question
add comment

3 Answers

up vote 11 down vote accepted

You can achieve this by passing the values to the standard field id's in the url. This technique is known as Salesforce URL hacking. It is described in detail in this excellent blog post by Ray Dehler.

In this instance, you'd retrieve the standard id of the "Amount" field, and then use this Id in the url to assign a static value to the Amount field. Override the standard "New Opportunity" button to redirect to this url, and you are set to go.

Assuming "opp7" is the standard id of the Amount field, the url will look like:

https://eu1.salesforce.com/006/e?retURL=%2F001D000000rCa6i&accid=001D000000rCa6i& opp7=100

The output is:

enter image description here

Update: Based on the feedback in comments, i've modified the answer to include the standard id. But the id's for custom fields might change from one org to another(Thanks @peter-knoll for pointing that out), you also might want to use this in combination with custom settings as a workaround to hardcoding the ids(which is never a good idea).

Update2: You can also use the API name for standard fields, so instead of using "opp7" above you can use "Amount" in the url. This only works for standard fields though.

Update3: Andrew Fawcett has blogged about an even better and elegant solution for this issue here.

Anup

share|improve this answer
1  
Won't the IDs will be different from sandbox to production? For that they could be stored in a Custom Setting record, I suppose. –  Peter Knolle Aug 28 '12 at 13:59
1  
@PeterKnolle Instead of hard code the Field Id use the salesforce standard Id. For the opportunity Amount field it is opp7 **https://eu1.salesforce.com/006/e?retURL=%2F001D000000rCa6i&accid=001D000000rCa‌​6i&opp7=100** –  Karanraj Aug 28 '12 at 14:05
1  
@Karanraj, that works if you are not using custom fields/objects. Otherwise you have to use the id of the field (or prefix of the custom object) –  ebt Aug 28 '12 at 16:39
1  
If a field is created in production, and then the sandbox is refreshed, the field ID will be the same in both orgs. –  Jeremy Nottingham Aug 28 '12 at 21:25
1  
Custom Settings could be used for that, but someone would have to manually populate them in both production and sandbox, since field Ids aren't available through any API or Apex. –  Jeremy Nottingham Aug 28 '12 at 21:27
show 2 more comments

I haven't yet had a chance to try it, but the following post details a method of creating VF pages that redirect to the standard New record page with field defaults by dynamically figuring out the field IDs.

It's a hack, but a very clever one.

http://force201.wordpress.com/2012/01/22/hack-to-find-field-ids-allows-a-default-ui-new-page-to-be-pre-populated/

share|improve this answer
add comment

In case you need to pass values for custom fields, or deal with record types etc., you can also refer to this series of blog posts on URL Hacking - http://writeforce.blogspot.com/2012/12/prepopulating-fields-using-url-hacking.html

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.