You need to sign in to do that
Don't have an account?
Michał Bajdek 28
prechat, save picklist value to case
Hello gyus, I would like to save value from picklist to Case created by LiveAgent. How can I store value picked from User to created Case to Other_Results__c field ?
public without sharing class Prechat_ApexController { public static List<String> values {get;set;} public Prechat_ApexController(){ values = getPickListValuesIntoList(); } private static List<String> getPickListValuesIntoList(){ List<String> pickListValuesList= new List<String>(); Schema.DescribeFieldResult fieldResult = Case.Other_Results__c.getDescribe(); List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues(); for( Schema.PicklistEntry pickListVal : ple){ pickListValuesList.add(pickListVal.getLabel()); } return pickListValuesList; } }here is my visualforcepage:
<apex:page showHeader="false" lightningStylesheets="true" controller="Prechat_ApexController"> <!-- This script takes the endpoint URL parameter passed from the deployment page and makes it the action for the form --> <script type='text/javascript'> (function() { function handlePageLoad() { var endpointMatcher = new RegExp("[\\?\\&]endpoint=([^&#]*)"); document.getElementById('prechatForm').setAttribute('action', decodeURIComponent(endpointMatcher.exec(document.location.search)[1])); } if (window.addEventListener) { window.addEventListener('load', handlePageLoad, false); } else { window.attachEvent('onload', handlePageLoad, false); }})(); </script> <div class="center"> <div class="center"> <h1>{!$Label.Prechat_Header}</h1> </div> <div id="logo_wrapper" class="center"> <apex:image url="{!$Resource.BrandLogo}" width="150" /> </div> <!-- Form that gathers information from the chat visitor and sets the values to Live Agent Custom Details used later in the example --> <form method='post' id='prechatForm'> <div class="slds-col slds-size_1-of-2 center"> Email: </div> <div class="slds-col slds-size_1-of-2 center"> <input type='text' name='liveagent.prechat:ContactEmail' id='email' /><br /> </div> <div class="slds-col slds-size_1-of-2 center"> Reason : </div> <div class="slds-col slds-size_1-of-2 center"> <select name="liveagent.prechat:Other_Results__c" id='reasonForContact' required="true" class="input selectProd"> <apex:repeat value="{!values}" var="prodcat"> <option value="{!prodcat}">{!prodcat}</option> </apex:repeat> </select> </div> <!-- Hidden fields used to set additional custom details --> <input type="hidden" name="liveagent.prechat:CaseStatus" value="New" /><br /> <!-- This example assumes that "Chat" was added as picklist value to the Case Origin field --> <input type="hidden" name="liveagent.prechat:CaseOrigin" value="Chat" /><br /> <!-- This example will set the Case Record Type to a specific value for the record type configured on the org. Lookup the case record type's id on your org and set it here --> <!--<input type="hidden" name="liveagent.prechat:CaseRecordType" value="012D00123456789" />--> <!-- map: Use the data from prechat form to map it to the Salesforce record's fields --> <input type="hidden" name="liveagent.prechat.findorcreate.map:Contact" value="FirstName,ContactFirstName;LastName,ContactLastName;Email,ContactEmail;Phone,ContactPhone" /> <input type="hidden" name="liveagent.prechat.findorcreate.map:Case" value="Other_Results__c,Status,CaseStatus;Origin,CaseOrigin;RecordTypeId,CaseRecordType" /> <!-- doFind, doCreate and isExactMatch example for a Contact: Find a contact whose Email exactly matches the value provided by the customer in the form If there's no match, then create a Contact record and set it's First Name, Last Name, Email, and Phone to the values provided by the customer --> <input type="hidden" name="liveagent.prechat.findorcreate.map.doFind:Contact" value="Email,true" /> <input type="hidden" name="liveagent.prechat.findorcreate.map.isExactMatch:Contact" value="Email,true" /> <input type="hidden" name="liveagent.prechat.findorcreate.map.doCreate:Contact" value="FirstName,true;LastName,true;Email,true;Phone,true" /> <!-- doCreate example for a Case: create a case to attach to the chat, set the Case Subject to the value provided by the customer and set the case's Status and Origin fields --> <input type="hidden" name="liveagent.prechat.findorcreate.map.doCreate:Case" value="Reason_for_Chat__c,true;Status,true;Origin,true;RecordTypeId,true" /> <!-- linkToEntity: Set the record Contact record, found/created above, as the Contact on the Case that's created --> <input type="hidden" name="liveagent.prechat.findorcreate.linkToEntity:Contact" value="Case,ContactId" /> <!-- showOnCreate: Open the Contact and Case records as sub-tabs to the chat for the agent in the Console --> <input type="hidden" name="liveagent.prechat.findorcreate.showOnCreate:Contact" value="true" /> <!--potentially to delete--> <input type="hidden" name="liveagent.prechat.findorcreate.showOnCreate:Account" value="true" /> <input type="hidden" name="liveagent.prechat.findorcreate.showOnCreate:Case" value="true" /> <!-- saveToTranscript: Associates the records found / created, i.e. Contact and Case, to the Live Chat Transcript record. --> <input type="hidden" name="liveagent.prechat.findorcreate.saveToTranscript:Contact" value="ContactId" /> <input type="hidden" name="liveagent.prechat.findorcreate.saveToTranscript:Case" value="CaseId" /> <!-- displayToAgent: Hides the case record type from the agent --> <input type="hidden" name="liveagent.prechat.findorcreate.displayToAgent:CaseRecordType" value="false" /> <!-- searchKnowledge: Searches knowledge article based on the text, this assumes that Knowledge is setup --> <input type="hidden" name="liveagent.prechat.knowledgeSearch:CaseSubject" value="true" /> <div class="center"> <input type='submit' value='Chat Now' id='prechat_submit' onclick="setName()"/> </div> <!-- Set the visitor's name for the agent in the Console to first and last name provided by the customer --> <script type="text/javascript"> function setName() { document.getElementById("prechat_field_name").value = document.getElementById("firstName").value + " " + document.getElementById("lastName").value; } </script> <style type="text/css"> .center{ margin: auto; width: 100%; padding: 5px; margin-left: 50px; } p { font-weight: bolder; } #logo_wrapper { margin-top: 10px; margin-bottom: 10px; } </style> </form> </div> </apex:page>
Aditya Vijayvargiya
Did you get any solution to this question?