Skip to content

"INVALID_FIELD_FOR_INSERT_UPDATE" when using SFParentChildrenSyncUpTarget #3145

@Yannmm

Description

@Yannmm

Please fill out the following details:

  1. Version of Mobile SDK Used: 7.3.0
  2. Issue found in Native App or Hybrid App: Native swift
  3. OS Version: 13.1
  4. Device: iPad pro
  5. Steps to reproduce:

Assume we have two classes "Parent" and "Child".

class Parent {
    let id: String
}

class Child {
    let id: String
    let parent_id: String
    let option: String
}

And my sync up configure file is like below:

{
    "syncs": [{
        "syncName": "UpSync",
        "syncType": "syncUp",
        "soupName": "soup_parent",
        "target": {
            "iOSImpl": "SFParentChildrenSyncUpTarget",
            "childrenCreateFieldlist": [
                "Id",
                "Parent_id",
                "Option"
            ],
            "parentCreateFieldlist": [
                "Id",
            ],
            "childrenUpdateFieldlist": [
                "Option"
            ],
            "parentUpdateFieldlist": [
            ],
            "parent": {
                "idFieldName": "Id",
                "sobjectType": "Parent__c",
                "modificationDateFieldName": "LastModifiedDate",
                "soupName": "soup_parent"
            },
            "relationshipType": "MASTER_DETAIL",
            "type": "rest",
            "modificationDateFieldName": "LastModifiedDate",
            "children": {
                "parentIdFieldName": "Parent_id",
                "idFieldName": "Id",
                "sobjectType": "Child__c",
                "modificationDateFieldName": "LastModifiedDate",
                "soupName": "soup_child",
                "sobjectTypePlural": "children__r"
            },
        },
        "options": {"mergeMode":"LEAVE_IF_CHANGED"}
    }]
}

Using this configuration, create and delete is working fine. But when I want to update, child record always receive 400, and the reponse is like:

{
    "body":[
        {
            "message":"Unable to create/update fields: parent_id. Please check the security settings of this field and verify that it is read/write for your profile or permission set.",
            "errorCode":"INVALID_FIELD_FOR_INSERT_UPDATE",
            "fields":[
                "parent_id"
            ]
        }
    ],
    "httpHeaders":{

    },
    "httpStatusCode":400,
    "referenceId":"a8le0000000IB31AAG"
}

Request body is like:

{
    "body":{
        "parent_id":"a0be0000009Za0qAAC",
        "option":"No"
    },
    "method":"PATCH",
    "referenceId":"a8le0000000IB31AAG",
    "url":"/services/data/v46.0/sobjects/child__c/a8le0000000IB31AAG"
}

So I guess SFDC won't allow me to update parent_id, and that's reasonable. The question is why this key-value pair is inserted into request, despite I already declare update field list contains only option.

After I looking at sdk code, I found in file SFParentChildrenSyncUpTarget.m line 417, there is code like this:

       if (parentId) {
            fields[((SFChildrenInfo *) info).parentIdFieldName] = useParentIdReference ? [NSString stringWithFormat:@"@{%@.%@}", parentId, kCreatedId] : parentId;
        }

This will insert above key-value pair into the request body. But I think this is only required when creating, not updating. So I add one more condition:

        if (parentId && isCreate) { // only insert when create
            fields[((SFChildrenInfo *) info).parentIdFieldName] = useParentIdReference ? [NSString stringWithFormat:@"@{%@.%@}", parentId, kCreatedId] : parentId;
        }

And it works like a charm.

How do you think?
please let me know. Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions