In a question I asked last week about getting namespaces, the best solution was to get information about the class (or any class) in the namespaced package.
But this seems vulnerable if there are other classes with the same name. It also assumes that the utility class is packaged with the object whose namespace we want.
What I really want is to get the namespace that a field belongs to, because the get() and put() methods on an object are namespaced.
So I have to say
Account a = [SELECT some account];
a.put('namespace__Field__c', 35);
not
Account a = [SELECT some account];
a.put('Field__c', 35);
Can I query a fields namespace, to make the above operation more robust?
[The context of this question: We emulate roll-up summary functionality in a trigger, with a "group by" on a Type__c field. We then take the field on Account that matches the "type" and assign it the count in its corresponding group.]