[SalesForce] Is it possible to upsert Prechat data in a custom Lightning Snap-in

Here are some related links:

  1. Custom Pre-Chat Component Sample Using Aura
  2. Custom Pre-Chat Component Sample Using JavaScript
  3. Find and Create Records Pre-Chat API Code Sample

Based on link 3, it seems like if we were using a Visualforce Page for our Prechat form, we would be able to upsert a single Contact record, in order to associate the LiveChatTranscript to an existing record. However, I'm having a hard time hunting down how that would be done using a custom Lightning Component hooked up to a Snap-in, as described in link 1.

We're trying to do the association based on a Unique External Id field. When an existing value is populated in the Prechat form, no Contact record is created nor associated to the LiveChatTranscript. When a new value is populated, a new Contact is created and associated. The behavior observed so far seems to indicate any DML failures are silent, and the transcript record can be created regardless of any failures up to that point.

I can't find any documentation on the Prechat API surfaced via the lightningsnapin:prechatAPI component. It doesn't seem to have any sort of analogue to the findOrCreate map that would have allowed us to upsert in classic.

Is it possible to have a Lightning Prechat Snap-in upsert a Contact record based on a Unique External Id field included in the prechat form? If so, how?

Best Answer

The Snap-Ins for Web Developer Guide contains this page:

Pre-Chat Code Examples

Find contacts but don't create new ones

In this example, we don't want to create contact records — we only want to find them. To disable creation of a record, set doCreate to false for all the required fields for the record. This code disables a common default behavior of creating a contact record with each chat session.

 embedded_svc.settings.extraPrechatInfo = [{
   "entityFieldMaps": [{
     "doCreate":false,
     "doFind":true,
     "fieldName":"LastName",
     "isExactMatch":true,
     "label":"Last Name"
   }, {
     "doCreate":false,
     "doFind":true,
     "fieldName":"FirstName",
     "isExactMatch":true,
     "label":"First Name"
   }, {
     "doCreate":false,
     "doFind":true,
     "fieldName":"Email",
     "isExactMatch":true,
     "label":"Email"
   }],
   "entityName":"Contact"
 }];