fflib-apex-common icon indicating copy to clipboard operation
fflib-apex-common copied to clipboard

fflib_QueryFactory().selectFieldSet() fails with when FieldSet queries namespaced fields

Open rsoesemann opened this issue 11 years ago • 9 comments
trafficstars

I have a valid FieldSet that contains field of a managed Custom Object and some fields of a related objects

When I run this code in unmanaged namespace-less org

new fflib_QueryFactory(CustomObject__c.SObjectType)
            .selectFieldSet(SObjectType.CustomObject__c.Fieldsets.MyFieldSet)

it perfectly works. When try the same in a managed org with namespace (make Cusom Object and the related Object part of this namespace) it fails with:

caused by: UP2GO_2F.fflib_QueryFactory.InvalidFieldException: Invalid field 'NAMESPACE__Field__c' for object 'NAMESPACE__CustomObject__c'

Class.NAMESPACE.fflib_QueryFactory.getFieldToken: line 95, column 1
Class.NAMESPACE.fflib_QueryFactory.selectFieldSet: line 276, column 1
Class.NAMESPACE.fflib_QueryFactory.selectFieldSet: line 262, column 1
Class.NAMESPACE.MasterPartSelectCtrlExt: line 94, column 1

rsoesemann avatar Aug 13 '14 10:08 rsoesemann

@capeterson one for you? :+1:

afawcett avatar Aug 13 '14 10:08 afawcett

Looks like it. I'll dig in shortly and see what can be done. On Aug 13, 2014 3:52 AM, "Andrew Fawcett" [email protected] wrote:

@capeterson https://github.com/capeterson one for you? [image: :+1:]

— Reply to this email directly or view it on GitHub https://github.com/financialforcedev/fflib-apex-common/issues/24#issuecomment-52033985 .

capeterson avatar Aug 13 '14 17:08 capeterson

This might be connected to this Know Issue: https://success.salesforce.com/issues_view?id=a1p30000000SzK3AAK

rsoesemann avatar Aug 15 '14 10:08 rsoesemann

@afawcett from looking at the class I think the root cause lies out side this class and instead in fflib_SObjectDescribe

rsoesemann avatar Aug 18 '14 10:08 rsoesemann

@afawcett and @capeterson I hope I could fix this in pull request https://github.com/financialforcedev/fflib-apex-common/pull/25

rsoesemann avatar Aug 18 '14 13:08 rsoesemann

Taking a look at this I have to ask if it actually fixed the issue for you? The fflib_SObjectDescribe.getField method delegates to the FieldsMap.get implementation which already lower-cases the input at that level. Although of course it's late and I may be missing some detail.

capeterson avatar Aug 21 '14 04:08 capeterson

It's true that you store the field names in lower case in your Describe cache class, but you definitly do not lower case the field names you extract from a Fieldsets FieldSetMember.

FieldSetMember myField = ...
String stillMixedCase = myField.getFieldPath();
...getFieldToken(stillMixedCase);
Schema.DescribeSObjectResult describe = getDescribe();
Schema.SObjectField field = describe.getField(stillMixedCase);

rsoesemann avatar Aug 21 '14 13:08 rsoesemann

Hi @up2go-rsoesemann is there still an issue here? @capeterson whats your thoughts?

afawcett avatar Jun 06 '15 09:06 afawcett

If it's still an issue certainly needs to be fixed, I also need to reconcile the private and public versions, I think we've had a few bug fixes on the internal version I need to migrate to this repo.

capeterson avatar Jun 07 '15 21:06 capeterson