If you are planning to default input field values in an edit page for an Sobject, then you need to use something cryptic, like LKID hack. This hack requires you to pass field’s IDs as URL query params with default values for each, like:
This solution is really a hack, as there is no way in Apex describe information to know ID for a given sobject field. This makes your app or solution tough to port across the orgs, developers try to use custom settings to declare all such LKID fields, each one of them must be correctly updated by Admin post app installation.
One hack, and the easiest solution so far !
Keith Clarke has done a great job to solve this problem in best possible way as of now on platform. Here are few posts and thoughts from Keith about the same:
- Long time back post on how to use LKID for populating the screen with field values : http://force201.wordpress.com/2010/03/14/new-child-object-default-ui-page-via-urlfor/
- Idea to make this LKID hack more documented : http://force201.wordpress.com/2010/03/27/lkid-hack-value-is-fragile/, link to the idea (http://success.salesforce.com/ideaView?id=08730000000Gt4QAAS)
- A solution that makes it possible to know field ids : http://force201.wordpress.com/2012/01/23/outputting-a-url-that-has-keys-that-only-differ-by-case/
IdeaExchange - Field ID needed in Apex Describe Info !
I appreciate efforts and the solution from Keith Clarke, but the approaches we still have are hacky and prone to failures. It would make our life much simpler, if Apex describe information includes information about the field ID also. For ex.
Schema.DescribeFieldResult f = Schema.sObjectType.Account.fields.Name; // This new method is very much required Id fieldId = f.getId();
I am posting the same as an Idea, please promote it to make developer’s life easier in future. Here is the link to the idea : https://sites.secure.force.com/success/ideaView?id=08730000000gM7mAAE