I'm trying to create an account automatically when a user starts a live agent chat. This user is a community user, which means I should already know all of his information including contactId, account number, etc. I have read all of the live agent development guide, but it only shows examples of creating contacts and cases. When I tried to use a similar approach it did not work. This is what's shown in the development guide:

<form method="post" action="#">
<input type='hidden' name='liveagent.prechat:ContactFirstName' value='{!$User.firstname}'/>
<input type='hidden' name='liveagent.prechat:ContactLastName' value='{!$User.lastname}' />
<input type='text' name='liveagent.prechat:CaseSubject' placeholder='Subject'/>
<input type="hidden" name="liveagent.prechat.findorcreate.map:Contact" value="FirstName,ContactFirstName;LastName,ContactLastName" />
<input type="hidden" name="liveagent.prechat.findorcreate.map.doFind:Contact" value="FirstName,true;LastName,true" />
<input type="hidden" name="liveagent.prechat.findorcreate.map.isExactMatch:Contact" value="FirstName,true;LastName,true" />
<input type="hidden" name="liveagent.prechat.findorcreate.map.doCreate:Contact" value="FirstName,true;LastName,true" />
<input type="hidden" name="liveagent.prechat.findorcreate.saveToTranscript:Contact" value="ContactId" />
<input type="hidden" name="liveagent.prechat.findorcreate.showOnCreate:Contact" value="true" />
<input type="hidden" name="liveagent.prechat.findorcreate.linkToEntity:Contact" value="Case,ContactId" />
<input type="hidden" name="liveagent.prechat.findorcreate.map:Case" value="Subject,CaseSubject;Status,CaseStatus" />
<input type="hidden" name="liveagent.prechat.findorcreate.map.doCreate:Case" value="Subject,true;Status,true" />
<input type="submit" value="Submit" />

I have tried to use a similar format like this:

<input type='hidden' name='liveagent.prechat:AccountName' value='{!$Account.accountname}'/>
<input type="hidden" name="liveagent.prechat.findorcreate.map:Account" value="Account,AccountName" />
<input type="hidden" name="liveagent.prechat.findorcreate.map.doFind:Account" value="AccountName,true" />
<input type="hidden" name="liveagent.prechat.findorcreate.map.isExactMatch:Account" value="Account,true;" />
<input type="hidden" name="liveagent.prechat.findorcreate.map.doCreate:Account" value="AccountName,true" />
<input type="hidden" name="liveagent.prechat.findorcreate.saveToTranscript:Account" value="AccountId" />
<input type="hidden" name="liveagent.prechat.findorcreate.showOnCreate:Contact" value="true" />
<input type="hidden" name="liveagent.prechat.findorcreate.linkToEntity:Contact" value="Case,ContactId" />

I'll appreciate all the help! Thanks.

1 Answer 1


You can use Javascript Remoting, add a script to your VF page that passes the chat variables to an apex class that does the logic:

See the example below:

VF Page:

<input type='hidden' name='liveagent.prechat:AccountName' id="acc"/>

    $(document).ready(function() { 
        console.log('Calling Your_Controller...');
        try {
                function(result, event) {
                    if (event.status) {
                        document.getElementById('acc').value = result.AccountName;
                        var formValid = document.forms["prechatForm"].checkValidity();
                        return formValid;
                }, {
                    escape: false
        } catch (ex) {
            return false;

The controller:

    global without sharing class Your_Controller {

    global static boolean Your_Controller_Method() {
        User user = [select Id, ContactId from User where id =: UserInfo.getUserId()];
        // now you have the user so you can find the contact and then the account details
        Account acc = [SELECT id, Name FROM Account......];
        if (acc != null)
            return acc;


See the documentation: JavaScript Remoting for Apex Controllers

You must log in to answer this question.

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