I am trying to make a Live Agent Pre Chat Form inside our Salesforce Customer Community using visualforce. I've tried out a lot of approaches and cannot figure out how to use custom picklist fields (including dependent picklists) and get them to appear in the Service Cloud Console or map into the case that is created. Has anyone done this before?
Here is my in progress code:
Visualforce Page:
<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>
<img src="{!$Resource.Live_Agent_Logo}"/><p/>
<apex:outputText style="font-weight:bold;font-size:14px;color:#595959;padding:0 10px;" value="Chat with Technical Support"/><p/>
<div id="chatFormDiv">
<!-- Get chat visitor info and set for Live Agent -->
<form method='post' id='prechatForm'>
<apex:form>
<apex:outputPanel id="inputFields">
<div style="width:600px; height:auto; float:left; text-align:left;">
<apex:outputText style="font-weight:bold;font-size:12px;color:#595959;float:left;padding:0 10px;" value="Product:"/>
<apex:inputField id="inputProduct" value="{!newCase.Affected_Product__c}" styleClass="picklist" required="true">
<apex:actionsupport event="onchange" action="{!validateInputFields}" rerender="inputFields">
<apex:param value="{!newCase.Affected_Product__c}" assignTo="{!caseProduct}" name="caseProduct"/>
</apex:actionsupport>
</apex:inputField>
</div><br/>
<div style="width:600px; height:auto; float:left; text-align:left;">
<apex:outputText style="font-weight:bold;font-size:12px;color:#595959;float:left;padding:0 10px;" value="Version:"/>
<apex:inputField id="inputVersion" value="{!newCase.Version__c}" styleClass="picklist" onchange="pushVersion();" required="true"></apex:inputField>
<apex:actionRegion>
<apex:actionFunction name="pushVersion" action="{!getCaseProduct}" reRender="inputFields" immediate="true">
<apex:param value="{!newCase.Version__c}" assignTo="{!caseVersion}" name="caseVersion"/>
</apex:actionFunction>
</apex:actionRegion>
</div><br/>
</apex:outputPanel>
<div style="width:600px; height:auto; float:left; text-align:left;">
<apex:outputText style="font-weight:bold;font-size:12px;color:#595959;float:left;padding:0 10px;" value="Category:"/>
<apex:inputField value="{!newCase.Request_Type__c}" styleClass="picklist" required="true"></apex:inputField>
</div><br/>
<div style="width:600px; height:auto; float:left; text-align:left;">
<apex:outputText style="font-weight:bold;font-size:12px;color:#595959;float:left;padding:0 10px;" value="Topic:"/>
<apex:inputField value="{!newCase.Problem_Type__c}" styleClass="picklist" required="true"></apex:inputField><p/>
</div><br/>
<apex:outputText style="font-weight:bold;font-size:12px;color:#595959;float:left;padding:0 10px;" value="Provide a brief describe of the issue:"/>
<apex:inputField value="{!newCase.Subject}" styleClass="textarea" html-placeholder="How we can help?" required="true"></apex:inputField>
<!-- Hidden Collection Fields -->
<input type="hidden" name="liveagent.prechat:CaseContactId" id="contactId" value="{!contactId}"/>
<input type="hidden" name="liveagent.prechat:CaseAccountId" id="accountId" value="{!contactAccountId}"/>
<input type="hidden" name="liveagent.prechat:ContactFirstName" id="firstName" value="{!contactFirstName}"/>
<input type="hidden" name="liveagent.prechat:ContactLastName" id="lastName" value="{!contactLastName}"/>
<input type="hidden" name="liveagent.prechat:ContactEmail" id="email" value="{!contactEmail}"/>
<input type="hidden" name="liveagent.prechat:CaseSubject" id="subject" value="{!caseSubject}"/>
<input type="hidden" name="liveagent.prechat:CaseDescription" id="description" value="{!newCase.Description}"/>
<input type="hidden" name="liveagent.prechat:CaseStatus" value="New"/>
<input type="hidden" name="liveagent.prechat:CaseOrigin" value="Live Chat"/>
<input type="hidden" name="liveagent.prechat:CaseProduct" id="product" value="{!caseProduct}"/>
<input type="hidden" name="liveagent.prechat:CaseProductVersion" id="version" value="{!caseVersion}"/>
<input type="hidden" name="liveagent.prechat:CaseRequestType" id="requestType" value="{!newCase.Request_Type__c}"/>
<input type="hidden" name="liveagent.prechat:CaseProblemType" id="problemType" value="{!newCase.Problem_Type__c}"/>
<input type="hidden" name="liveagent.prechat:CaseRecordType" value="012F0000000zp0x"/>
<input type="hidden" name="liveagent.prechat.name" id="prechat_field_name"/>
<!-- Map Contact Fields via Form -->
<input type="hidden" name="liveagent.prechat.findorcreate.map:Contact" value="Id,CaseContactId;FirstName,ContactFirstName;LastName,ContactLastName;Email,ContactEmail"/>
<!-- Map Case Fields via Form -->
<input type="hidden" name="liveagent.prechat.findorcreate.map:Case" value="Subject,CaseSubject;Status,CaseStatus;Origin,CaseOrigin;Description,CaseSubject;Affected_Product__c,CaseProduct;Version__c,CaseProductVersion;Request_Type__c,CaseRequestType;Problem_Type__c,CaseProblemType;ContactId,CaseContactId;AccountId,CaseAccountId;RecordTypeId,CaseRecordType"/>
<!-- Find Contact and Match or Create -->
<input type="hidden" name="liveagent.prechat.findorcreate.map.doFind:Contact" value="Id,true"/>
<input type="hidden" name="liveagent.prechat.findorcreate.map.isExactMatch:Contact" value="Id,true"/>
<input type="hidden" name="liveagent.prechat.findorcreate.map.doCreate:Contact" value="FirstName,true;LastName,true;Email,true;Phone,true"/>
<!-- Create Case and attach Chat Details -->
<input type="hidden" name="liveagent.prechat.findorcreate.map.doFind:Case" value="CaseNumber,true"/>
<input type="hidden" name="liveagent.prechat.findorcreate.map.isExactMatch:Case" value="CaseNumber,true"/>
<input type="hidden" name="liveagent.prechat.findorcreate.map.doCreate:Case" value="Subject,true;Status,true;Origin,true;Description,true;Affected_Product__c,true;Version__c,true;Request_Type__c,true;Problem_Type__c,true;ContactId,true;AccountId,true;RecordTypeId,true"/>
<!-- Link Contact to New Case -->
<input type="hidden" name="liveagent.prechat.findorcreate.linkToEntity:Contact" value="Case,ContactId"/>
<!-- Display Contact and Case as sub-tabs in Live Agent Console -->
<input type="hidden" name="liveagent.prechat.findorcreate.showOnCreate:Contact" value="true"/>
<input type="hidden" name="liveagent.prechat.findorcreate.showOnCreate:Case" value="true"/>
<!-- Link Chat Transcript to Contact and Case -->
<input type="hidden" name="liveagent.prechat.findorcreate.saveToTranscript:Contact" value="ContactId"/>
<input type="hidden" name="liveagent.prechat.findorcreate.saveToTranscript:Case" value="CaseId"/>
<!-- Hide Case Record Type from Agent -->
<input type="hidden" name="liveagent.prechat.findorcreate.displayToAgent:CaseRecordType" value="false"/>
<!-- Start Chat Button -->
<p/><input type='submit' value='REQUEST A CHAT' id='prechat_sbumit' onclick="setName()"/>
<!-- Set Chat Visitor name in Live Agent Console -->
<script type="text/javascript">
function setName(){
document.getElementById("prechat_field_name").value =
document.getElementById("firstName").value + " " + document.getElementById("lastName").value;
}
</script>
</apex:outputPanel>
</apex:form>
</form>
</div>
<!-- CSS -->
<style>
.picklist{
width:300px;
height:20px;
background: #fff;
border: 1px solid #CCCCCC;
border-radius: 5px;
margin-bottom: 5px;
padding: 0 10px;
}
select{
width:300px;
height:20px;
background: #fff;
border: 1px solid #CCCCCC;
border-radius: 5px;
margin-bottom: 5px;
padding: 0 10px;
}
.textarea{
width:450px;
height: 100px;
background: #fff;
border: 1px solid #CCCCCC;
border-radius: 5px;
margin-bottom: 5px;
padding: 0 10px;
}
</style>
<style>
body{
background-color:#fff;
}
#chatFormDiv
{
width:300px;
text-align:center;
padding:5px;
}
#chatHeader
{
color:#6d6d6d;
font-size:18px;
font-weight:bold;
float: center;
}
#prechat_submit
{
font-weight:bold;
float: center;
}
label
{
width:150px;
font-weight:bold;
}
input[type=text], textarea
{
height: 50px;
width:400px;
background: #fff;
border: 1px solid #CCCCCC;
border-radius: 5px;
margin-bottom: 5px;
padding: 0 10px;
}
input[type=email]
{
height: 30px;
width:280px;
background: #fff;
border: 1px solid #CCCCCC;
border-radius: 3px;
margin-bottom: 5px;
padding: 0 10px;
}
input[type=tel]
{
height: 30px;
width:280px;
background: #fff;
border: 1px solid #CCCCCC;
border-radius: 3px;
margin-bottom: 5px;
padding: 0 10px;
}
input[type=text]
{
height: 30px;
}
textarea{
height:140px;
padding-top: 10px;
padding-bottom: 10px;
}
.chatStatusDiv
{
display:none;
}
</style>
</apex:page>
Controller:
public class CommunityPreChatController {
private ApexPages.StandardController stdCtrl;
public Case newCase {get;set;}
public String caseSubject {get;set;}
public String caseProduct {get;set;}
public String caseVersion {get;set;}
public Id contactId {get;set;}
public Id contactAccountId {get;set;}
public String contactFirstName {get;set;}
public String contactLastName {get;set;}
public String contactEmail {get;set;}
public Datetime currentDateTime {get;set;}
public Boolean formComplete {get;set;}
public CommunityPreChatController(ApexPages.StandardController stdController) {
stdCtrl = stdController;
newCase = (Case) stdctrl.getRecord();
//newCase = new Case();
newCase.Status = 'New';
getCurrentUserContact();
currentDateTime = Datetime.now();
}
public void getCurrentUserContact(){
User u = [SELECT Id, ContactId, Contact.AccountId, Contact.FirstName, Contact.LastName, Contact.Email FROM User WHERE Id=:UserInfo.getUserId() LIMIT 1];
contactId = u.ContactId;
contactAccountId = u.Contact.AccountId;
contactFirstName = u.Contact.FirstName;
contactLastName = u.Contact.LastName;
contactEmail = u.Contact.Email;
}
}
Best Answer
How to show dependent picklist in PreChat form.
It seems that PrechartForm couldn't render
apex:inputfield
component and bind SObject field. I've found that we could display primitive property initialized within controller. Knowing this, we could solve problem with displaying picklist by implementing next steps:Custom PrechartForm controller:
Code above will return Type and custom Cards__c picklistvalues:
Visualforce could get this from controller by:
In your prechatForm, you should add JS and html markup:
Add right after you input elements:
Div component will be used for picklist creation
Add field
Type
to.map:Case
and.map.doCreate:Case
:Note that field name here is case sensitive
Whole Prechat Form with JavaScript:
Result:
Chosen custom picklist value arrives in agent console.
I've used code snippets from: broc.seib and Benj