[SalesForce] Live Agent Case creation from Pre Chat

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.

Markup

Best Answer

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.

Related Topic