2

I wrote some code to get field names. I see these two different functions in the DescribeFieldResult Class. But I don't see any real time difference when I run the below code in console. How are they different?

for (Schema.SObjectType sObjectTypeVar : Schema.getGlobalDescribe().values())
{
    Schema.DescribeSObjectResult objResult = sObjectTypeVar.getDescribe();
    System.debug(objResult.getLocalName()+ '::'+objResult.getName());
}
  • 2
    It only matters if you have a namespace – Eric Apr 7 '17 at 13:37
  • I still see both name space in both methods... CTO__test1__c :: CTO__test1__c – bharath Apr 7 '17 at 14:11
  • Are you running this i the org that IS the CTO Namespace? – Eric Apr 7 '17 at 14:24
  • Yes. i have name space CTO in the same org – bharath Apr 7 '17 at 14:26
  • 1
    Not "have it" in the org set as the CTO org. Meaning the org is a DE org and you have set the namespace of the org to CTO. – Eric Apr 7 '17 at 15:03
3

Here is what I get in my DE org with a namespace (for this example say NS):

NS__My_Test_Object__c.sObjectType.getDescribe().getLocalName();
NS__My_Test_Object__c.sObjectType.getDescribe().getName();

Debug outputs as

My_Test_Object__c
NS__My_Test_Object__c

This is in the org where I have the NS set

Check via going to:

Setup -> Create -> Packages

enter image description here

If you do not see CTO next to the Namespace Prefix then CTO is not local and thus localName will include CTO__

| improve this answer | |
3

From the same documentation you linked in your question:

getLocalName: Returns the name of the field, similar to the getName method. However, if the field is part of the current namespace, the namespace portion of the name is omitted.

This would imply that the getName method would return the namespace as part of the name, regardless of what namespace you are currently working in.

| improve this answer | |
  • I am still seeing both having same namespace in the debug statement. – bharath Apr 7 '17 at 14:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.