How to access lookup object value using Salesforce composite connector "Create sobject tree" in Mule 4

1k views Asked by At

I want to insert data into 2 objects (say Employee__c and Contacts) which have parent-child relation using the Salesforce Composite Connector method Create sobject tree. Few fields have a lookup object. I want to pass the external ID field value to this lookup object and fetch the value. But it looks like Create sobject tree doesn't support using lookup logic. Can someone shed light on how this can be achieved?

Sample Code that I tried. In the Employee__c table, I have an Account__c field that has a lookup to Account object and here I am trying to reference that using the external ID field. I know for lookup we need to use as Account__r, this works in normal Salesforce connector but it is not working in the composite connector.

payload.records map ((record , indexOfRecord) -> {
    "attributes": {
        "type": "Employee__c",
        "referenceId": record.attributes.referenceId
    },
    "Name": record.Name,
    "Website": record.Website,
    **"Account__r": {
        'Employee_Number__c': record.EmployeeNumber, 
        'type': 'Account'
    }**,
    "Contacts": {
        "records": record.Contacts.records map ((record01, indexOfRecord01) -> {
            "attributes": {
                "type": "Contact",
                "referenceId": record01.attributes.referenceId
            },
            "LastName": record01.LastName,
            "Email": record01.Email,
            "Title": record01.Title
        })
    }
})

Any ideas or suggestions would be greatly appreciated.

Thanks in advance

0

There are 0 answers