function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Quentin CotillardQuentin Cotillard 

How can I set a lead recordType from a live agent pre-chat form?

I am trying to create a new lead record when a new chat is initiated after filling in a pre-chat form.
My probleme is that instead of opening a new lead tab with the information filled in by the user, I get a "Select Lead Record Type" tab where the agent has to select the record type for the lead. Once they select the recordtype the lead has none of the information provided.
I can't have a default recordType set since the recordType is going to be definied by user input.
I have seen many questions regarding this issue but none have a working solution.

Here is the visualforce pre-chat form I have:

<form method='post' id='prechatForm'> 
      <label for="liveagent.prechat:FirstNameDetail">First Name:</label>
          <input type='text' name='liveagent.prechat:FirstNameDetail' required='true' /><br />
      <label for="liveagent.prechat:LastNameDetail">Last Name:</label>
          <input type='text' name='liveagent.prechat:LastNameDetail' required='true' /><br />
      <label for="liveagent.prechat:EmailDetail">Email Address:</label>
          <input type='email' name='liveagent.prechat:EmailDetail' required='true' /><br />
      <label for="liveagent.prechat:provider">Are you a provider?:</label>
          <input type="radio" name="liveagent.prechat:provider" value="yes" required='true'/> Yes
          <input type="radio" name="liveagent.prechat:provider" value="no" required='true'/> No
      <div id="zipfield" style="display: none;">
          <label for="liveagent.prechat:ZipDetail">Zip code:</label> <input type='text' name='liveagent.prechat:ZipDetail'/>
      </div>
      
      <input type="hidden" name="liveagent.prechat:leadStatus" value="Open" />
      <input type="hidden" name="liveagent.prechat:Company" value="none" />
      <input type="hidden" name="liveagent.prechat:RecordType" value="01260000000YLBs" />

      <!-- Map input to lead fields -->
      <input type="hidden" name="liveagent.prechat.findorcreate.map:lead"
        value="FirstName,FirstNameDetail;LastName,LastNameDetail;Company,Company;Email,EmailDetail;Status,leadStatus;RecordType,RecordType" />


      <!-- Try to find the Lead by email (exact match) -->
      <input type="hidden" name="liveagent.prechat.findorcreate.map.doFind:Lead"
        value="Email,true" />
      <input type="hidden" name="liveagent.prechat.findorcreate.map.isExactMatch:Lead"
        value="Email,true;" />


      <!-- If the Lead is not found, then create one with the following fields set -->
      <input type="hidden" name="liveagent.prechat.findorcreate.map.doCreate:Lead"
        value="FirstName,true;LastName,true;Email,true;Company,true;Status,true;RecordType,true" />
 

      <!-- If a new Lead record has been created, open it as a subtab -->
      <input type="hidden" name="liveagent.prechat.findorcreate.showOnCreate:Lead"
        value="true" />
        
      <!-- displayToAgent: Hides the lead record type from the agent -->
      <input type="hidden" name="liveagent.prechat.findorcreate.displayToAgent:RecordType" value="false" />

      <!-- Save the Lead id to transcript's field ContactId -->
      <input type="hidden" name="liveagent.prechat.findorcreate.saveToTranscript:Lead"
        value="LeadId" />

     <input type= "hidden" name= "liveagent.prechat.findorcreate.displayToAgent: String detailName" value= "Boolean display" />
      <div id="submit">  
          <input type='submit' value='Request Chat' id='prechat_submit'/>
      </div>
</form>
James Boutel 10James Boutel 10
any update on this? I have the same issue
sriram lingamallu 7sriram lingamallu 7
You can use the below logic to set a record type in the pre-chat form page.
  • Create a label in the org - Live_Agent_Lead_RT and use it in the hidden fields.
<input type="hidden" name="liveagent.prechat:RecordType" value="{!$Label.Live_Agent_Lead_RT}" />
honda57honda57
Hi Sririam.  I am having the same problem.  I tried your solution with the custom label and that doesn't seem to work either.

User-added image


<!--hidden fields written to the new lead-->
            <input type="hidden" name="liveagent.prechat:leadStatus" value="New Lead" />
            <input type="hidden" name="liveagent.prechat:leadSource" value="Web Chat - QDC" />
            <input type="hidden" name="liveagent.prechat:RecordType" value="{!$Label.Live_Chat_Label_for_Record_Type}" />

 
honda57honda57
I figured out why my code wasn't working.  We have a few validation rules that require data in fields behind the scenes (i.e. not at the field level or page layout level).  I had to adjust those validation rules and now it is working fine.