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:
https://na1.salesforce.com/a02/e?CF00N30000001cYtG={!Case.CaseNumber}&CF00N30000001cYtG_lkid={!Case.Id}&retURL=%2F{!Case.Id}&saveURL=%2F{!Case.Id}
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
Comments (2)
Anonymoussays:
March 26, 2012 at 7:23 pmWe definitely need this. Thanks for creating the idea Abhinav. I too had an extra deployment when migrating from one env to other as we get a new field id in each one. :-(wish something like this was there now. But anyways, hope to see it in future. Voted for the idea 🙂
Anonymoussays:
March 26, 2012 at 7:31 pmsame here Swaleh, it would be great help if it comes as a feature