I'm doing a CRUD check on Field level, since under some weird circumstances our customers don't have update rights on Record level, but only on fields (it's a guest license). So in addition to the fflib_SObjectDomain CRUD check on Record level, we had to implement an additional check on field level. It worked, but it's still failing in a view cases with a null pointer in this line:

&& !field.getDescribe().isUpdateable()

but I have no idea how the field or it's describe could be null. Anyone out there any idea? Additional info: there are different record types.

Map<String, Schema.SObjectField> allFields = records.getSObjectType().getDescribe().fields.getMap();    

for(SObject record : records) {
    Map<String, Object> recordFields = record.getPopulatedFieldsAsMap();
    for(String fieldName : recordFields.keySet()) {
        Schema.SObjectField field = allFields.get(fieldName);

        if(record.get(field) != oldRecords.get(record.Id).get(field)
                && !field.getDescribe().isUpdateable()) {
            return false;
  • Weird. Is field null or field.getDescribe() null? Suggest you System.debug(JSON.serializePretty(allFields)) and System.debug(JSON.serializePretty(recordFields)) if field is null to see what is going on. – Keith C May 11 '18 at 7:53
  • Hm It's a customers org and we had no option to reproduce it since we don't have access to guest licenses :( But I'll put this into the next patch and disable crud for now. Thanks for the serialize pretty hint, never used that :) – Basti May 11 '18 at 8:11
  • hmm upload failed: Apex Type unsupported in JSON: Schema.SObjectField – Basti May 11 '18 at 10:20
  • Sorry didn't realise that. I guess it will have to be System.debug(JSON.serializePretty(allFields.keySet())) and also System.debug('fieldName=' + fieldName + ' field=' + field). – Keith C May 11 '18 at 10:30

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.