3

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());
}
6
  • 2
    It only matters if you have a namespace
    – Eric
    Apr 7, 2017 at 13:37
  • I still see both name space in both methods... CTO__test1__c :: CTO__test1__c
    – bharath
    Apr 7, 2017 at 14:11
  • Are you running this i the org that IS the CTO Namespace?
    – Eric
    Apr 7, 2017 at 14:24
  • Yes. i have name space CTO in the same org
    – bharath
    Apr 7, 2017 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, 2017 at 15:03

2 Answers 2

5

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__

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.

1
  • I am still seeing both having same namespace in the debug statement.
    – bharath
    Apr 7, 2017 at 14:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .