I try to create a case as soon as I accept the chat. The case record type should be picked from the guest user profile which I mentioned only one, but in console the case gets created with the default type. I have mentioned the case record type tag as well, but still it is not working.


3 Answers 3


Method One : PreChat API Only (Record Type by ID)

Create a hidden input field that will host the Record Type by Id, because RecordType Name is not supported in live agent:

<input type="hidden" name="liveagent.prechat.caseRecordType" value="RECORDTYPEID" />

Then in your findorcreate.map, make sure you are mapping caseRecordType to RecordTypeId in Salesforce, like this (you will likely have other items in your map too, but I removed mine for simplicity in this answer and only left RecordType:

<input type="hidden" name="liveagent.prechat.findorcreate.map:Case" value="RecordTypeId,caseRecordType" />

Then, lastly, in your findorcreate.map:DoCreate, make sure you include RecordTypeId,true:

<input type="hidden" name="liveagent.prechat.findorcreate.map.doCreate:Case" value="RecordTypeId,true;Origin,true;Subject,true;Status,true;" />

As noted by another answerer, the downside to this implementation is that you will need to change the hard coded RecordTypeId in the preChat VF page when deploying it to a production org, since the RecordTypeId will be different.

Method Two : PreChat API and Workflow Rule (Record Type by Name)

Using the PreChat API, we have the ability to set any field on the case object, similarly to the way that we are setting record type in Method One. StackExchange user PepeFloyd suggests that if you are setting any of your values to a unique value that is only used during a live agent chat, then you can also add a workflow rule that fires off of meeting that criteria that sets the record type for you.

First we set our unique value on the case object. In this example, we set the case origin to "Chat" and assume that "Chat" is never used as the origin in any other scenario. We then add it to the map, and the doCreate:

<input type="hidden" name="liveagent.prechat.caseOrigin" value="Chat" />
<input type="hidden" name="liveagent.prechat.findorcreate.map:Case" value="Origin,caseOrigin" />
<input type="hidden" name="liveagent.prechat.findorcreate.map.doCreate:Case" value="Origin,true;" />

Then our Workflow Rule would look something like this:

Workflow Rule for Case Origin

And our Field Update:

Workflow Field Update for Record Type

You would of course set it to your appropriate Record Type.

  • 1
    It's easier to do and maintain this with a workflow rule.
    – PepeFloyd
    Dec 25, 2015 at 11:52
  • @PepeFloyd - Just be curious to do that, Can you please tell me??
    – sfdc rowdy
    Dec 26, 2015 at 7:37
  • 1
    @sfdcrowdy For example, if you were populating the new case via pre-chat api with the value "Chat" for the field "Origin" you could have a workflow rule that would update the record type via field update based on the origin value.
    – PepeFloyd
    Dec 26, 2015 at 8:50
  • Great idea Pepe! I'll update my answer to include it. Dec 28, 2015 at 15:18
  • Why don't you just query for your recordtypeid and set it as a variable so you don't have to statically type it? String recordTypeId = [SELECT id from RecordType WHERE SobjectType = 'Case' AND Name = 'myCustomRecordTypeName'].get(0).id; Feb 17, 2016 at 20:21

I doubt there is some internal mechanism to query recordtypeId here ,one of the following ways to address this problem is use hardcoded recordtype Id as below

<input type="hidden" name="liveagent.prechat:caseRecordType" value="573a00000000001" /> 
<input type="hidden" name="liveagent.prechat.findorcreate.map:Case" value="Origin,caseOrigin;Subject,caseSubject;RecordtypeId,caseRecordType;" />

Only drawback i see is in production you may need to change the recordtypeId copied using developer console or set up menu


I have also found that if part of your case creation has a need to link to an existing contact, and you want to find the contact by email address and with a specific record type (like 'Customer') then we have a similar problem. You need to hard code a record id for the contact.

Because 'liveagent.prechat.findorcreate.map.doFind:Contact' can't be filtered with a record type name. But it can with a RecordTypeId

You must log in to answer this question.

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