I'm experiencing a very odd behaviour in my SF org. I have two classes that have an identical method:
/* works */ public with sharing class classA { public static void getFieldDescriptions(sObjectType objType) { System.debug('Fields: ' + objType.getDescribe().fields.getMap().size()); } } /* does not work */ public with sharing class classB { public static void getFieldDescriptions(sObjectType objType) { System.debug('Fields: ' + objType.getDescribe().fields.getMap().size()); } }
Both classes are API v.34. One is new (created a couple of days ago), the other one about half a year and was just recently moved to v34.
Problem is: When calling either class's describe method (e.g. from the dev console), only one class lists all fields (standard + custom) fields - the other one doesn't (only custom). Since I did not add any fields to the Task object, one function thus returns 0 and the other one thirtysomething.
Sample invocation: classB.getFieldDescriptions(Task.sObjectType)
When outputting one map:
{accountid=AccountId, activitydate=ActivityDate, calldisposition=CallDisposition, calldurationinseconds=CallDurationInSeconds, callobject=CallObject, calltype=CallType, createdbyid=CreatedById, createddate=CreatedDate, description=Description, id=Id, ...}
the other:
{}
I'm logged in as a System Administrator, have full access to all objects, classes and fields (checked FLS) and can reproduce the problem for every other object as well: One class's method will return only the number of custom fields - the other one all fields (which of course is my goal). What I cannot do however is reproduce the issue in another org.
What else might (or might not) be relevant: There's a managed package being developed in the org. The first time I noticed the problem I was able to "fix" it by deleting and recreating the Apex class - after that all fields were returned even though no changes were made to the underlying code. I can't do that for the classes mentioned above however, since they're part of our managed package (which has already been deployed)...
Any thoughts or ideas that might point me into the right direction? I know this sounds strange but I've spends hours after hours narrowing it down but in the end didn't get anywhere. Any help is appreciated!
EDIT: Since describing in classA works fine I tried this: When I add another method to classA:
public static void callB()
{
classB.getFieldDescriptions(Task.sObjectType);
}
and invoke it, the result will also be 0.