Newer Version Available
Follow Pre-Chat Code Examples
Find contacts but don't create new ones
In this example, we don't want to create contact records — we only want to find them. To disable creation of a record, set doCreate to false for all the required fields for the record. This code disables a common default behavior of creating a contact record with each chat session.
1embedded_svc.settings.extraPrechatInfo = [{
2 "entityFieldMaps": [{
3 "doCreate":false,
4 "doFind":true,
5 "fieldName":"LastName",
6 "isExactMatch":true,
7 "label":"Last Name"
8 }, {
9 "doCreate":false,
10 "doFind":true,
11 "fieldName":"FirstName",
12 "isExactMatch":true,
13 "label":"First Name"
14 }, {
15 "doCreate":false,
16 "doFind":true,
17 "fieldName":"Email",
18 "isExactMatch":true,
19 "label":"Email"
20 }],
21 "entityName":"Contact"
22}];Don’t attach records to the chat transcript
If you don’t want to attach contact records to the transcript, set saveToTranscript to an empty string.
1embedded_svc.settings.extraPrechatInfo = [{
2 "entityFieldMaps": [{
3 "doCreate":true,
4 "doFind":true,
5 "fieldName":"LastName",
6 "isExactMatch":true,
7 "label":"Last Name"
8 }, {
9 "doCreate":true,
10 "doFind":true,
11 "fieldName":"FirstName",
12 "isExactMatch":true,
13 "label":"First Name"
14 }, {
15 "doCreate":true,
16 "doFind":true,
17 "fieldName":"Email",
18 "isExactMatch":true,
19 "label":"Email"
20 }],
21 "entityName":"Contact",
22 "saveToTranscript": ""
23}];Attach a record to a custom field on the chat transcript
If you want to attach the created case or contact record to a custom field on the transcript, use saveToTranscript.
1embedded_svc.settings.extraPrechatInfo = [{
2 "entityFieldMaps": [{
3 "doCreate": true,
4 "doFind": true,
5 "fieldName": "LastName",
6 "isExactMatch": true,
7 "label": "Last Name"
8 }, {
9 "doCreate": true,
10 "doFind": true,
11 "fieldName": "FirstName",
12 "isExactMatch": true,
13 "label": "First Name"
14 }, {
15 "doCreate": true,
16 "doFind": true,
17 "fieldName": "Email",
18 "isExactMatch": true,
19 "label": "Email"
20 }],
21 "entityName": "Contact",
22 "saveToTranscript": "customContact__c"
23}];Don’t show the created record to the agent
If you don’t want to show the created record when the chat session starts, set showOnCreate to false.
1embedded_svc.settings.extraPrechatInfo = [{
2 "entityFieldMaps": [{
3 "doCreate": true,
4 "doFind": true,
5 "fieldName": "LastName",
6 "isExactMatch": true,
7 "label": "Last Name"
8 }, {
9 "doCreate": true,
10 "doFind": true,
11 "fieldName": "FirstName",
12 "isExactMatch": true,
13 "label": "First Name"
14 }, {
15 "doCreate": true,
16 "doFind": true,
17 "fieldName": "Email",
18 "isExactMatch": true,
19 "label": "Email"
20 }],
21 "entityName": "Contact",
22 "showOnCreate": false
23}];Override fields specified in your org’s setup
This example overrides the first name, last name, and subject passed in from the pre-chat form. To test this code, select the service scenario in your org’s setup and add this code to your snippet.
1embedded_svc.settings.extraPrechatFormDetails = [{
2 "label": "First Name",
3 "value": "John",
4 "displayToAgent": true
5}, {
6 "label": "Last Name",
7 "value": "Doe",
8 "displayToAgent": true
9}, {
10 "label": "Email",
11 "value": "john.doe@salesforce.com",
12 "displayToAgent": true
13}, {
14 "label": "issue",
15 "value": "Overriding your setup",
16 "displayToAgent": true
17}];
18
19embedded_svc.settings.extraPrechatInfo = [{
20 "entityName": "Contact",
21 "showOnCreate": true,
22 "linkToEntityName": "Case",
23 "linkToEntityField": "ContactId",
24 "saveToTranscript": "ContactId",
25 "entityFieldMaps": [{
26 "isExactMatch": true,
27 "fieldName": "FirstName",
28 "doCreate": true,
29 "doFind": true,
30 "label": "First Name"
31 }, {
32 "isExactMatch": true,
33 "fieldName": "LastName",
34 "doCreate": true,
35 "doFind": true,
36 "label": "Last Name"
37 }, {
38 "isExactMatch": true,
39 "fieldName": "Email",
40 "doCreate": true,
41 "doFind": true,
42 "label": "Email"
43 }]
44}, {
45 "entityName": "Case",
46 "showOnCreate": true,
47 "saveToTranscript": "CaseId",
48 "entityFieldMaps": [{
49 "isExactMatch": false,
50 "fieldName": "Subject",
51 "doCreate": true,
52 "doFind": false,
53 "label": "issue"
54 }, {
55 "isExactMatch": false,
56 "fieldName": "Status",
57 "doCreate": true,
58 "doFind": false,
59 "label": "Status"
60 }, {
61 "isExactMatch": false,
62 "fieldName": "Origin",
63 "doCreate": true,
64 "doFind": false,
65 "label": "Origin"
66 }]
67}]Create a new record from a different Salesforce object
If your business needs a record from a Salesforce object that isn’t available in the standard scenarios, you can define the object in extraPrechatInfo. For example, you can create an account when a chat session starts.
1embedded_svc.settings.extraPrechatInfo = [{
2 "entityName": "Contact",
3 "entityFieldMaps": [{
4 "isExactMatch": true,
5 "fieldName": "FirstName",
6 "doCreate": true,
7 "doFind": true,
8 "label": "firstName"
9 }, {
10 "isExactMatch": true,
11 "fieldName": "LastName",
12 "doCreate": true,
13 "doFind": true,
14 "label": "LastName"
15 }, {
16 "isExactMatch": true,
17 "fieldName": "Email",
18 "doCreate": true,
19 "doFind": true,
20 "label": "Email"
21 }]
22}, {
23 "entityName": "Case",
24 "entityFieldMaps": [{
25 "isExactMatch": false,
26 "fieldName": "Subject",
27 "doCreate": true,
28 "doFind": false,
29 "label": "issue"
30 }, {
31 "isExactMatch": false,
32 "fieldName": "Status",
33 "doCreate": true,
34 "doFind": false,
35 "label": "Status"
36 }, {
37 "isExactMatch": false,
38 "fieldName": "Origin",
39 "doCreate": true,
40 "doFind": false,
41 "label": "Origin"
42 }]
43}, {
44 "entityName": "Account",
45 "entityFieldMaps": [{
46 "isExactMatch": true,
47 "fieldName": "Name",
48 "doCreate": true,
49 "doFind": true,
50 "label": "LastName"
51 }]
52}];
53embedded_svc.settings.extraPrechatFormDetails = [{
54 "label": "firstName",
55 "value": "John",
56 "displayToAgent": true
57}, {
58 "label": "LastName",
59 "value": "Doe",
60 "displayToAgent": false
61}, {
62 "label": "Email",
63 "value": "john.doe@salesforce.com",
64 "displayToAgent": true
65}, {
66 "label": "issue",
67 "value": "Do the work",
68 "displayToAgent": true
69}];Link to another Salesforce object
If you want to link the case record created by Embedded Chat to the account record you created from extraPrechatInfo, use linkToEntityName and linkToEntityFieldName.
1embedded_svc.settings.extraPrechatInfo = [{
2 "entityName": "Account",
3 "linkToEntityName": "Case",
4 "linkToEntityField": "AccountId",
5 "entityFieldMaps": [{
6 "isExactMatch": true,
7 "fieldName": "Name",
8 "doCreate": true,
9 "doFind": true,
10 "label": "LastName"
11 }]
12}];
13
14embedded_svc.settings.extraPrechatFormDetails = [{
15 "label": "firstName",
16 "value": "Jane",
17 "displayToAgent": true
18}, {
19 "label": "LastName",
20 "value": "Doe",
21 "displayToAgent": false
22}, {
23 "label": "Email",
24 "value": "jane.doe@gmail.com",
25 "displayToAgent": true
26}, {
27 "label": "issue",
28 "value": "Do the work",
29 "displayToAgent": true
30}];Don’t attach a contact to a case
If you don’t want the default link between a contact and a case, set linkToEntityName to an empty string.
1embedded_svc.settings.extraPrechatInfo = [{
2 "entityFieldMaps": [{
3 "doCreate": true,
4 "doFind": true,
5 "fieldName": "LastName",
6 "isExactMatch": true,
7 "label": "Last Name"
8 }, {
9 "doCreate": true,
10 "doFind": true,
11 "fieldName": "FirstName",
12 "isExactMatch": true,
13 "label": "First Name"
14 }, {
15 "doCreate": true,
16 "doFind": true,
17 "fieldName": "Email",
18 "isExactMatch": true,
19 "label": "Email"
20 }],
21 "entityName": "Contact",
22 "linkToEntityName": ""
23}];Disable pre-chat and pass along the user's name
If you want to avoid the pre-chat form but still have the user’s name show up in the Waiting state, you can:
- Find the object that contains "label" : "First Name".
- Add a property "name" : "FirstName".
- Set the value of the "value" property to the desired first name value. For example, "value" : "Jane".
1embedded_svc.settings.extraPrechatFormDetails = [{
2 "label":"First Name",
3 "name":"FirstName",
4 "value":"Jane",
5 "displayToAgent":true
6}, {
7 "label":"Last Name",
8 "value":"Doe",
9 "displayToAgent":true
10}, {
11 "label":"Email",
12 "value":"jane.doe@salesforce.com",
13 "displayToAgent":true
14}, {
15 "label":"issue",
16 "value":"Sales forecasts",
17 "displayToAgent":true
18}];
19
20embedded_svc.settings.extraPrechatInfo = [{
21 "entityName":"Contact",
22 "showOnCreate":true,
23 "linkToEntityName":"Case",
24 "linkToEntityField":"ContactId",
25 "saveToTranscript":"ContactId",
26 "entityFieldMaps": [{
27 "isExactMatch":true,
28 "fieldName":"FirstName",
29 "doCreate":true,
30 "doFind":true,
31 "label":"First Name"
32 }, {
33 "isExactMatch":true,
34 "fieldName":"LastName",
35 "doCreate":true,
36 "doFind":true,
37 "label":"Last Name"
38 }, {
39 "isExactMatch":true,
40 "fieldName":"Email",
41 "doCreate":true,
42 "doFind":true,
43 "label":"Email"
44 }]
45}, {
46 "entityName":"Case",
47 "showOnCreate":true,
48 "saveToTranscript":"CaseId",
49 "entityFieldMaps": [{
50 "isExactMatch":false,
51 "fieldName":"Subject",
52 "doCreate":true,
53 "doFind":false,
54 "label":"issue"
55 }, {
56 "isExactMatch":false,
57 "fieldName":"Status",
58 "doCreate":true,
59 "doFind":false,
60 "label":"Status"
61 }, {
62 "isExactMatch":false,
63 "fieldName":"Origin",
64 "doCreate":true,
65 "doFind":false,
66 "label":"Origin"
67 }]
68}];Set custom fields on the transcript object
If you want to set custom fields on the transcript object, pass those fields in as transcript fields in prechatFormDetails. This code assumes you created a custom field called CartValue on the chat transcript object.
1embedded_svc.settings.extraPrechatFormDetails = [{
2 "label":"CartValue",
3 "value":”200”,
4 "transcriptFields":[ "CartValue__c" ],
5 "displayToAgent":true
6}];Save pre-chat form values into a custom field on the transcript object
- Create a custom field on the transcript object (for example, LastName__c).
- Pass the transcript fields in the extra pre-chat form details without passing the value property.
The value is calculated from the pre-chat form and saved into the custom field.
1embedded_svc.settings.extraPrechatFormDetails = [{"label":"Last Name", "transcriptFields": ["LastName__c"]}];