1

This logic is being used in a migration from one object (Case) to another object (Care_Recipient_File__c).

There are hundreds of fields on both objects, many of them have the same api names and store the same data points. The ones that differ are handled with a field mapping var, which I've omitted here.

I've verified that when I only copy data from our manually prepared field map, the data migrates succesfully. However, I can run this in exec anon right now and get the same error I got with my batch class:

        // Querying all fields from Case
    Case c = Database.query('SELECT ' + String.join(new List<String>(Schema.SObjectType.Case.fields.getMap().keySet()), ', ') + ' FROM Case WHERE Id = :sourceCaseId');


    // Update fields from provided map
    for (String caseField : diffFieldMap.keySet()) {
        String crfField = diffFieldMap.get(caseField);
        crf.put(crfField, c.get(caseField));
    }

    // Update fields with matching api names
    Map<String, Schema.SObjectField> crfFieldsMap = Schema.SObjectType.Care_Recipient_File__c.fields.getMap();
    for (String fieldName : crfFieldsMap.keySet()) {
        if (c.getSObjectType().getDescribe().fields.getMap().containsKey(fieldName) && crfFieldsMap.get(fieldName).getDescribe().isUpdateable()) {
            crf.put(fieldName, c.get(fieldName));
        }
    }

When attempting to update said CRF record, I get

Line: 22, Column: 1 System.DmlException: Update failed. First exception on row 0 with id a0ZPb000000CBBkMAO; first error: INSUFFICIENT_ACCESS_OR_READONLY, insufficient access rights on object id: []

I've confirmed that there's no issue with running the dynamic query on the case object that pulls all its fields.

Since I'm checking isUpdateable() on each matching crf field before attempting to populate, I'm unsure of why I'm getting this access error, since I'm a system admin with full crud and FLS edit permissions.

My best solution so far is to write a batch class just to try and migrate one field at a time between the two records until an offending field is found, but I'm wondering if there's something more obvious that anyone can suggest?

1 Answer 1

1

Well that was fast...

I haven't fully confirmed yet, but as soon as I excluded standard fields from the set of fields to copy over it succeeded.

The standard fields that were excluded were RecordTypeId and OwnerId.

I'm guessing the error message is a bit misleading, and the issue was that I was copying over a recordtypeid that isn't valid for the new object, and the system assumed I simply couldn't see that recordtypeid due to lack of access.

2
  • You can get this sort of error message against lookup type fields (and record type) when the contextual user doesn't have at least read permission for the related object type (or record type). Perhaps you have not assigned all record types to the user?
    – Phil W
    Commented Jan 8 at 20:54
  • The issue was that that my script attempted to copy over a RecordTypeId that belonged to a different object. Error message turned out to be wrong on both counts, neither insufficient accesss nor read only, just a nonexistent Id.
    – smohyee
    Commented Jan 10 at 18:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .