Skip to main content
added 32 characters in body
Source Link
Kris Goncalves
  • 23.6k
  • 8
  • 40
  • 73

But I'm trying to create a Custom Object (ClientMember__cClientMember__c in our example) that have a lookup on Account

I tried this (CLIENTUID_FIELDCLIENTUID_FIELD or CLIENTUID_FIELD2CLIENTUID_FIELD2):

const fields = { Client__c : clientUIDInput.value }; 
const fields = { Client__c : clientUIDInput.value }; 

==> Malformed ID

Malformed ID

const fields = { Client__r : { Client_UID__c : clientUIDInput.value } }; 
const fields = { Client__r : { Client_UID__c : clientUIDInput.value } }; 

==> Field Client__r has value of unsupported data type:

Field Client__r has value of unsupported data type:

What do I have to do please ?to achieve this?

But I'm trying to create a Custom Object (ClientMember__c in our example) that have a lookup on Account

I tried this (CLIENTUID_FIELD or CLIENTUID_FIELD2):

const fields = { Client__c : clientUIDInput.value }; 

==> Malformed ID

const fields = { Client__r : { Client_UID__c : clientUIDInput.value } }; 

==> Field Client__r has value of unsupported data type:

What I have to do please ??

But I'm trying to create a Custom Object (ClientMember__c in our example) that have a lookup on Account

I tried this (CLIENTUID_FIELD or CLIENTUID_FIELD2):

const fields = { Client__c : clientUIDInput.value }; 

Malformed ID

const fields = { Client__r : { Client_UID__c : clientUIDInput.value } }; 

Field Client__r has value of unsupported data type:

What do I have to do to achieve this?

Source Link
Yaac0
  • 165
  • 2
  • 16

How to Create Record from LWC using External Id in lookup fields

I'm trying to create an object in LWC, without using Apex. So I found out that we can do that with CreateRecord from uiRecordApi :

But I'm trying to create a Custom Object (ClientMember__c in our example) that have a lookup on Account

I tried this (CLIENTUID_FIELD or CLIENTUID_FIELD2):

import { LightningElement } from 'lwc'; import { createRecord } from 'lightning/uiRecordApi'; import { ShowToastEvent } from 'lightning/platformShowToastEvent'; import CLM_OBJECT from '@salesforce/schema/ClientMember__c'; import CLIENTUID_FIELD from '@salesforce/schema/ClientMember__c.Client__r.Client_UID__c'; import CLIENTUID_FIELD2 from '@salesforce/schema/Account.Client_UID__c'; export default class testCreateRecordLWC extends LightningElement { handleCreateCM(){ let clientUIDInput = this.template.querySelector('lightning-input'); const fields = {}; fields[CLIENTUID_FIELD.fieldApiName] = clientUIDInput.value; const recordInput = { apiName: CLM_OBJECT.objectApiName, fields }; createRecord(recordInput) .then(cm =>{ this.dispatchEvent( new ShowToastEvent({ title: 'Success', message: 'New ClientMember__c has been created', variant: 'success', }), ); }) .catch(error => { console.log(error); this.dispatchEvent( new ShowToastEvent({ title: 'Error while creating ClientMember__c', message: error.body.message, variant: 'error', }), ); }); } } 

I get : POST_BODY_PARSE_ERROR

enter image description here

I also tried this:

const fields = { Client__c : clientUIDInput.value }; 

==> Malformed ID

or this:

const fields = { Client__r : { Client_UID__c : clientUIDInput.value } }; 

==> Field Client__r has value of unsupported data type:

What I have to do please ??