1

I have a parent object Cov__c and a child object Address__c. I have created a custom button on the Address__c related list on Cov__c, which, when clicked, navigates the user to a page layout depending on a picklist value on Cov__c. Here is the url of the custom button:

/a0Z/e?retURL={!Cov__c.Id}&Cov__c={!Cov__c.Id}&RecordType={!IF(ISPICKVAL(Cov__c.Risk__c,'Terr'), "012180000008Tw0","012180000008Tw5")}&ent=01I180000004KaV

On my Address__c object I have a lookup called Cov_c, which links to the Cov__c object, and I basically want to prepopulate that. I am not sure how to do that.

Tia.

2

There are many ways to do that. First you need to find the custom field ID.

Quick and easy

Declarative and quick way to do that will be either looking at the source code of the page (ctrl/command + U) or using a developer tool extension for your browser (in this example Firebug for Firefox). Hover on the field or find the field name in the source code and you'll notice the field ID parameter as per the screenshot below:

Custom Field ID

Since this field is a lookup, in the URL we need to specify 2 values, one for the name and another for the record ID that you want to look up to. So your URL should look like YourExistingUrlPath&CF00N9000000DMCnR=RecordName&CF00N9000000DMCnR_lkid=001900000136LSj. Note the _lkid which means lookup ID and references the record ID of the record that we want to pre populate the field with.

Note that this is a quick way to find the field ID and you should not be hard coding this ID in your button URL because the field will have a different ID when you deploy it or create it into another org. This is only good for performing a quick test.

The dynamic programmatic way

Prior to the tooling api becoming GA, a few of us came up with the idea to dynamically parse the source code of the page in APEX and run some regular expressions in order to find the field ID. I will not give you the code for that, it's considered a bad hack :). Instead here are a few links where you can see how that is achieved now with the tooling API. If you're not a coder then you'll need a developer's assistance for this.

Querying Custom Object and Field IDs via Tooling API

How to get the entity ID for a custom field in Apex?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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