+ Start a Discussion
David JobeDavid Jobe 

Changing Prechat from Contacts to Accounts

I am trying to rewrite the prechat apex that Salesforce gives you to link your chat with a contact to link it to an account. If it doesn't find a link, then not to create an account. I have to admit that I am a little out of my depth on how to change the code to fit that need. Any help would be appreciated. What I have built so far is below.

<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].replace("javascript:", ""))); } 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 /> Phone: <input type='text' name='liveagent.prechat:AccountPhone' id='phone' /><br /> Issue: <input type='text' name='liveagent.prechat:CaseSubject' id='subject' /><br /> <!-- Hidden fields used to set additional custom details --> <input type="hidden" name="liveagent.prechat:CaseStatus" value="New" /><br /> <!-- This example assumes that "Chat" was added as picklist value to the Case Origin field --> <input type="hidden" name="liveagent.prechat:CaseOrigin" value="Chat" /><br /> <!-- This example will set the Case Record Type to a specific value for the record type configured on the org. Lookup the case record type's id on your org and set it here --> <input type="hidden" name="liveagent.prechat:CaseRecordType" value="012j0000000zM7s" /> <!-- 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;Phone,AccountPhone" /> <input type="hidden" name="liveagent.prechat.findorcreate.map:Case" value="Subject,CaseSubject;Status,CaseStatus;Origin,CaseOrigin;RecordTypeId,CaseRecordType" /> <!-- doFind, doCreate and isExactMatch example for a Contact: Find a contact whose Email exactly matches the value provided by the customer in the form If there's no match, then create a Contact record and set it's First Name, Last Name, Email, and Phone 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;Email,true;Phone,true" /> <!-- doCreate example for a Case: create a case to attach to the chat, set the Case Subject to the value provided by the customer and set the case's Status and Origin fields --> <input type="hidden" name="liveagent.prechat.findorcreate.map.doCreate:Case" value="Subject,true;Status,true;Origin,true;RecordTypeId,true" /> <!-- linkToEntity: Set the record Contact record, found/created above, as the Contact on the Case that's created --> <input type="hidden" name="liveagent.prechat.findorcreate.linkToEntity:Account" value="Case,AccountId" /> <!-- showOnCreate: Open the Contact and Case records as sub-tabs to the chat for the agent in the Console --> <input type="hidden" name="liveagent.prechat.findorcreate.showOnCreate:Account" value="true" /> <input type="hidden" name="liveagent.prechat.findorcreate.showOnCreate:Case" value="true" /> <!-- saveToTranscript: Associates the records found / created, i.e. Contact and Case, to the Live Chat Transcript record. --> <input type="hidden" name="liveagent.prechat.findorcreate.saveToTranscript:Account" value="AccountId" /> <input type="hidden" name="liveagent.prechat.findorcreate.saveToTranscript:Case" value="CaseId" /> <!-- displayToAgent: Hides the case record type from the agent --> <input type="hidden" name="liveagent.prechat.findorcreate.displayToAgent:CaseRecordType" value="false" /> <!-- searchKnowledge: Searches knowledge article based on the text, this assumes that Knowledge is setup --> <input type="hidden" name="liveagent.prechat.knowledgeSearch:CaseSubject" value="true" /> <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>