+ Start a Discussion
CharleneSCharleneS 

Live chat link to existing account?

Hi,

I am trying to link a prechat form up to existing Accounts when it comes to Person Accounts. What is happening currently is regardless of details added the system is making a new account with contactId, what I need it to do is link up matching details (which is seems to not be able to manage) I looked at this thread but have not been successful at replicating the results.

The code I have used comes from the dev docs, edited to use Person Account.
 
<apex:page showHeader="false">

<!-- This script takes the endpoint URL parameter passed from the deployment page and makes it the action for the form -->
<script type='text/javascript'>
(function() {
function handlePageLoad() {
var endpointMatcher = new RegExp("[\\?\\&]endpoint=([^&#]*)");
document.getElementById('prechatForm').setAttribute('action',
decodeURIComponent(endpointMatcher.exec(document.location.search)[1]));
} if (window.addEventListener) {
window.addEventListener('load', handlePageLoad, false);
} else { window.attachEvent('onload', handlePageLoad, false);
}})();
</script>

<h1>Live Agent Pre-Chat Form</h1>

<!-- Form that gathers information from the chat visitor and sets the values to Live Agent Custom Details used later in the example -->
<form method='post' id='prechatForm'>
    First name: <input type='text' name='liveagent.prechat:AccountFirstName' id='firstName' /><br />
    Last name: <input type='text' name='liveagent.prechat:AccountLastName' id='lastName' /><br />
    Email: <input type='text' name='liveagent.prechat:AccountEmail' id='email' /><br />
    ZipCode: <input type='text' name='liveagent.prechat:AccountZipCode' id='zipcode' /><br />
    
    <!-- Used to set the visitor's name for the agent in the Console -->
    <input type="hidden" name="liveagent.prechat.name" id="prechat_field_name" />

<!-- map: Use the data from prechat form to map it to the Salesforce record's fields -->
<input type="hidden" name="liveagent.prechat.findorcreate.map:Account" value="FirstName,AccountFirstName;LastName,AccountLastName;Email,AccountEmail;ZipCode,AccountZipCode;RecordTypeId,'{!PersonRTId}'"" />

<!-- doFind, doCreate and isExactMatch example for a Account: 
    Find a Account whose Email exactly matches the value provided by the customer in the form 
    If there's no match, then create a Account record and set it's First Name, Last Name, Email, and ZipCode to the values provided by the customer -->
<input type="hidden" name="liveagent.prechat.findorcreate.map.doFind:Account" value="Email,true" />
<input type="hidden" name="liveagent.prechat.findorcreate.map.isExactMatch:Account" value="Email,true" />

<input type="hidden" name="liveagent.prechat.findorcreate.map.doCreate:Account" value="FirstName,true;LastName,true;PersonEmail,true;BillingPostalCode,true;Type,true;RecordTypeId,true" />
<input type="hidden" name="liveagent.prechat.findorcreate.saveToTranscript:Account" value="AccountId" />

<!-- showOnCreate: Open the Account records as sub-tabs to the chat for the agent in the Console -->
<input type="hidden" name="liveagent.prechat.findorcreate.showOnCreate:Account" value="true" />

<!-- saveToTranscript: Associates the records found / created, i.e. Account, to the Live Chat Transcript record. --> 
<input type="hidden" name="liveagent.prechat.findorcreate.saveToTranscript:Account" value="AccountId" />

<input type='submit' value='Chat Now' id='prechat_submit' onclick="setName()"/>

<!-- Set the visitor's name for the agent in the Console to first and last name provided by the customer -->
<script type="text/javascript">
   function setName() {
    document.getElementById("prechat_field_name").value =  
        document.getElementById("firstName").value + " " + document.getElementById("lastName").value;
    }
</script>

<style type="text/css">
p {font-weight: bolder }
</style>

</form>
</apex:page>

Any help will be appreciated in getting this to map correctly!

Kind regards,

Charlene
Park WalkerPark Walker
Hi,

If you're still trying to resolve this you may want to adjust the field names in your mapping. Since Person Accounts are account records with fields added from the Contact you find that there is no Email field. The correct name is PersonEmail. While this is correct in your doCreate it is not in your mapping and search.

The folllowing changes should resolve the problem:

<input type="hidden" name="liveagent.prechat.findorcreate.map:Account" value="FirstName,AccountFirstName; LastName,AccountLastName; PersonEmail,AccountEmail; ZipCode,AccountZipCode; RecordTypeId,'{!PersonRTId}'"" />

<input type="hidden" name="liveagent.prechat.findorcreate.map.doFind:Account" value="PersonEmail,true" />

<input type="hidden" name="liveagent.prechat.findorcreate.map.isExactMatch:Account" value="PersonEmail,true" />

You may also need to change the RecordId assignment. Since you do not appear to be using a controller {!PersonRTId} will not have a value. The easiest solution to this is to just copy the record id of your Person Account record and insert it directly in place of the variable. Also, you are referencing the Type field in your doCreate but you do not define it in the mapping. You should either define a value in the mapping or delete the field in the doCreate.

Hope this helps.