function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Shahin__cShahin__c 

Unit test - hardcoded custom field IDs

Hello people,


I'm new to SF. As a business requirement I have written a web-service which is used to populate the fields of a custom object. 

I achieved this by embedding parameters in the URL as explained here.

 

The trouble is that SF does not support getting the field IDs dynamically at run time. There is support for custom objects though like below:

 

String pageId  = Schema.getGlobalDescribe().get('Customer_setup_form__c').getDescribe().getKeyPrefix();

 

But I was hoping that you could do something similar for custom fields too.

As a result I had to hardcode the ID of the custom fields which I’m passing in the values for: e.g.

 

https://cs4.salesforce.com/a1G/e?00NP0000000X7dg=France&00NP0000000X7ds=15+rue+de+l%27Hotel+de+Ville++

 

 

This works fine on the test sandbox. I now need to deploy this to our production server and therefore need to write unit test classes. I know for a fact that the ID of these custom controls will change once deployed to a different server. I have therefore 2 questions:

 

1)     Is there a better way of NOT hard-coding these IDs and use Apex to dynamically retrieve them at run time?

2)     The unit test will be my first one to write and I need to know if it will work with these hard-coded IDs?

 

 Many thanks,

Shane

 

ErinForceErinForce

Did you ever figure this out? I can't even get the production field ID hard-coded to work like it does in the sandbox. I can find no difference between the orgs that would explain why the hard-coded field ID works in one and not the other. And yes, I edited the ID to match the appropriate field ID for the org.

 

Hell, I'd be okay if I could just get the hard-coded ID to work.