I'm attempting to create the New button
functionality on a visualforce page that will be hosted as a section of
detailed page layout. This vf page will surface child records of a parent detail page record . Think of
this as a manually constructed 'related list' ( which also includes a New button
for adding records )
My requirement: Pressing the New button
should take one to the standard salesforce New page
for the child record with the
parent record lookup pre-populated.
I suspect the answer can be found in the construction of an appropriate url but this is where I hit a slight snag.
The vf page will be part of a managed package so I will have no obvious way (to my mind at least) of
grabbing the custom field Id of the parent lookup field. (ie hard coded lkids
are not an option)
All ideas are very much appreciated
Best Answer
A Tooling API Solution
I've been able to try out a hunch I've had since I noticed CustomField support in the Tooling API and have worked up a means to dynamically query the Custom Field Id's via the supported Salesforce Tooling API. My fresh from the press blog entry here goes into more details, though here is a code sample taken from the accompanying GitHub repo.
This results in ....
Summary. There CustomField object has a little amount of queryable fields this way, basically DeveloperName, TableEnumOrId (custom object Id or standard object name) and NamespacePrefix. These should allow you to dynamically query for most use cases. Keep in mind the solution uses a callout from Apex to the Tooling API (REST version), so you will need to have a Remote Site setting for the Tooling API end point added to the org.