8

We develop a AppExchange package and are having an issue with middlename,suffix,informalname fields on the Contact object. The issue is these fields are returned through a describe call also filtering by isAccessible() == true. This list of fields is then sent to javascript which generates a REST query which returns an error invalid field for these. I'm assuming the issue is they are simply not enabled. Is there a way to determine through the describe information if these fields are enabled in the org?

Notes:

  • The API version for the class and REST call are V38
  • We have to handle the scenario where these fields are either enabled and disabled in the customer org

UPDATE:

Our javascript (in mobile app) calls the apex REST endpoint (endpoint and helper class both on API V38) and it returns middlename,suffix,informalname using code as follows:

Map<String,Schema.SObjectField> fldsMap = thisObj.getDescribe().fields.getMap();
            for (Schema.SObjectField sf : fldsMap.values()) 
            {
                DescribeFieldResult sfdescr = sf.getDescribe();

                if (sfdescr.isAccessible()) {
                    FieldDescWrapper resWrapper = new FieldDescWrapper();
                    resWrapper.name = sfdescr.getName();

                    String objName = sfdescr.getRelationshipName();

                    if(objName != null && (objName.contains('__c') || Ctl_RelationshipBuilder.whiteListedStandardObjects.contains(objName))) {
                        resWrapper.relLookup = objName+'.'+Util.returnNameFieldForObject(objName,false);
                    } else {
                        resWrapper.relLookup = null;
                    }

                    result.add(resWrapper);
                }
            }

If I run the following code in anon. apex I do NOT get the middlename,suffix,informalname fields.

Map<String,Schema.SObjectField> contactFieldMap = Schema.getGlobalDescribe().get('Contact').getDescribe().fields.getMap();
for (Schema.sobjectfield field : contactFieldMap.values()) {
            System.debug('field val : ' + field.getDescribe().getname());
        }

I've also tried running the above code in a VF page/controller with API versions of both set to V38 to eliminate any oddities from the anon. apex running in V41)

Outstanding questions:

  1. Why are these fields returning at all when they're not enabled in this org?
  2. Why are they only returning ONLY in the context of the REST endpoint ONLY in this org?

Your Answer

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

Browse other questions tagged or ask your own question.