-1

newbie here,

I am trying to create an LWC for moving data existing in a custom (Dump) object to the standard Contact object. This LWC will have a button, which when clicked will upsert the data present in the dump object to the contact object, matching the external IDs. However, I am struggling with creating the controller class and the Javascript for the LWC. I have the basic pseudocode for it. I would appreciate it if someone could help me with the codes. TIA

Here is the pseudocode/ proposed method:

  • get data from contacts in the controller class and store it in a list
  • get data from the dump object in the controller class and store it in a list
  • create two lists named 'contacts to insert' and 'contacts to update'
  • loop over the dump objects records
  • in the loop, check if the external ID exists in the list of contacts created earlier, if it does, add the dump object record to the 'contacts to update' list
  • else add it to the 'contacts to insert' list
  • insert the 'contacts to insert' list
  • update the 'contacts to update' list

End

BTW I have created the HTML script for the LWC component (button).

Please let me know if this approach can be improved and/or the code for the LWC controller class.

1 Answer 1

1

You can create a single List to Upsert the records by matching the External Id.

Please refer updating a records using external Id in Apex

In LWC Javascript, call the Apex method imperatively on HTML button click to perform the steps

You must log in to answer this question.

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