You need to sign in to do that
Don't have an account?
Programmatic lookup of custom object page name & field ids for pre-population
I am using the method documented in various posts to pre-populate default values in a standard page for a custom object. i.e. I when the user wants to create a new record for the object, I generate this URL in Apex:
https://na7.salesforce.com/a0G/e?00NA0000003UhJ8=2010
This will open up the standard new screen for a custom object (page name = aOG) and in a year field put in 2010 (field id = 00NA0000003UhJ8)
This works fine, however, if I move the code to a new org, the page name and field ID will be different.
Does anybody know if there is a way to dynamically figure out the page name for a custom object and a field id for a field so I can programmatically figure out the appropriate URL vs hard coding it)?
You can describe all sobjects to determine the 3 character abbreviation for a custom object by name.
I don't think there's anything you can do for the field id.
We normally store this information in custom settings.
All Answers
You can describe all sobjects to determine the 3 character abbreviation for a custom object by name.
I don't think there's anything you can do for the field id.
We normally store this information in custom settings.
Check if this is Useful.... I have explained very similar thing here
http://community.salesforce.com/t5/Visualforce-Development/Populating-lookup-on-a-visual-force-page/m-p/183907#M24330
at least the domain part you can omit, /a0G/e?00NA0000003UhJ8=2010 should work, too
For reference here is the code:
1) Lookup by object name in code:
Schema.SObjectType.YourCustomObject__c.getKeyPrefix();
2) Lookup by object name as String:
Schema.getGlobalDescribe().get('YourCustomObject__c').getDescribe().getKeyPrefix())
Note - would want to harden this for production by doing null check if object name not found