How do I prepopulate fields on a Standard layout?

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?



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: 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.


Source : Link , Question Author : Anup , Answer Author : Anup

Leave a Comment