You need to sign in to do that
Don't have an account?
How to get field Id by Apex Class
I know how to use apex to get Sobject prefix Id:
Schema.DescribeSObjectResult d = Schema.SObjectType.Reference_Opportunity__c ;
system.debug('======DescribeSObjectResult'+d.getKeyPrefix());
I have code:
<apex:commandButton value="Create new Reference Opportunity" onClick="window.open('https://cs4.salesforce.com/a0a/e?CF00NP0000000aoFc={!PXRB__c.Name}&CF00NP0000000aoFc_lkid={!PXRB__c.Id}&saveURL=%2F{!PXRB__c.Id}&retURL=%2F{!PXRB__c.Id}');"/>
this link will open an new screen for create new record under Reference_Opportunity__c, because this is child object of PXRB__C, so the default value will be put into PXRB_No__c field.
the "a0a" is the prefix of Sobject Reference_Opportunity__c
the "CF00NP0000000aoFc" is ID of the PXRB_No__c field in Sobject Reference_Opportunity__c
When we deploy into production, the SObject as well as the field Id will be different, so my question is how to get PXRB_No__c Id from production by using apex code.
Thanks.
Qingsong
if your sandbox is a full sandbox then there is no problem... by using the static id there....
we have full sandbox but this is not works for me because we had new fields and object created in sandbox after we refresh from production, when we deploy the new fields and object from sandbox to production, the Id was changed.
I had workwround -- but it need to be update on every sandbox refresh
this will not required manual change the ID when deploy the changes from sandbox to production, only need update the code whenever sandbox get refreshed.
thank you for the idea, this is basically i did in apex class with the static id, determinate the difference between sandbox and production.
Qingsong
then y can't u create a simple vf page to open a pop up for this scenario...
We tend to use custom settings rather than static values for this - as they can be maintained in production without having to deploy code changes.