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
Jonny SimmoJonny Simmo 

How can I access a prechatdetails array in Post Chat apex?

Hello,

I am implementing Live Agent chat. In the post chat page I can access a few values using the following syntax in a VisualForce page, for example:

<apex:outputText value="{!$CurrentPage.parameters.chatKey}" />

This would display the Chat Key.

I can access the Chat Key value in the Apex controller with the following code:

liveAgentChatKey = ApexPages.currentPage().getParameters().get('chatKey');

However another value I can display on the page looks like an array or list, it's called ChatDetails and displays like this on the page:

{"prechatDetails":[{"label":"CaseType",
                    "value":"General Query",
                    "entityMaps":[],
                    "transcriptFields":[],
                    "displayToAgent":"true",
                    "doKnowledgeSearch":false},
                   {"label":"CaseSubject",
                    "value":"Webchat Case",
                    "entityMaps":[],
                    "transcriptFields":[],
                    "displayToAgent":"true",
                    "doKnowledgeSearch":false},
                   {"label":"CaseStatus",
                    "value":"New",
                    "entityMaps":[],
                    "transcriptFields":[],
                    "displayToAgent":"true",
                    "doKnowledgeSearch":false},
                   {"label":"FullName",
                    "value":"tytyty",
                    "entityMaps":[],
                    "transcriptFields":[],
                    "displayToAgent":"true",
                    "doKnowledgeSearch":false},
                   {"label":"CaseOrigin",
                    "value":"Webchat",
                    "entityMaps":[],
                    "transcriptFields":[],
                    "displayToAgent":"true",
                    "doKnowledgeSearch":false},
                   {"label":"Policy_Type",
                    "value":"Cashplan",
                    "entityMaps":[],
                    "transcriptFields":[],
                    "displayToAgent":"true",
                    "doKnowledgeSearch":false},
                   {"label":"EmailId",
                    "value":"a1Pg00000011qsWEAQ",
                    "entityMaps":[],
                    "transcriptFields":[],
                    "displayToAgent":"true",
                    "doKnowledgeSearch":false},
                   {"label":"CaseRT",
                    "value":"012b0000000DhUIAA0",
                    "entityMaps":[],
                    "transcriptFields":[],
                    "displayToAgent":"true",
                    "doKnowledgeSearch":false}],
                   "geoLocation":{"countryCode":"GB",
                                  "longitude":-0.1300048828125,
                                  "countryName":"United Kingdom",
                                  "organization":"BT",
                                  "latitude":51.5},
                   "visitorId":"ad376c22-49d4-455c-921c-803f7b805d6d",
                   "customDetails":[],
                   "agent":{"userId":"005b0000001Ps0u",
                            "agentName":"Jon at Simplyhealth",
                            "transfer":0}}

Question is, if I was to bring this into a variable in the Apex controller, how can I access the different values?

I would access it like this in Apex, but I don't know what it is?
ApexPages.currentPage().getParameters().get('chatDetails');

What type of variable would I put it into?
And how would I get at the values?

Any help appreciated.




 
ShashankShashank (Salesforce Developers) 
You can try JSON parsing: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_json_jsonparser.htm