如何通过Salesforce Live Agent事后聊天表单更新现有联系人字段
Great question! Let’s walk through exactly how to set this up—since right now your flow only creates a new Case, we’ll extend it to update the existing Contact’s fields using the post-chat form data.
1. Configure the Post-Chat Form
First, build (or modify) your post-chat form to include the Contact fields you want to update:
- Go to Setup > Service Setup > Live Agent > Chat Settings > Post-Chat Configuration
- Create a new post-chat form (or edit your existing one)
- Add the fields you want to update on the Contact (e.g.,
Phone,MailingStreet,PreferredContactMethod) - Make sure to include a unique identifier field that can match the existing Contact (like
Email—this is critical for finding the right record to update)
2. Set Up Field Mapping & Contact Matching Logic
Next, map the post-chat form fields to the Contact object, and configure Salesforce to update the existing Contact instead of creating a new one:
- In the same Post-Chat Configuration screen, scroll to Field Mappings
- For each Contact field you added to the form, set the mapping:
- Select
Contactas the target object - Choose the corresponding Contact field (e.g., map post-chat "Phone" input to Contact
Phonefield)
- Select
- Under Contact Matching Rules, set the rule to find an existing Contact using your unique identifier (e.g., "Email equals the Email provided in the post-chat form")
- Uncheck the "Create new Contact if no match is found" checkbox if you only want to update existing Contacts (leave it checked if you want a fallback to create a new one if no match exists)
3. Handle Complex Logic with Apex Triggers or Flow (If Needed)
If you need custom logic (e.g., updating a Contact field based on chat transcript content, or conditional updates), use an Apex Trigger or Flow:
Example Apex Trigger (Case After Insert)
Since Live Agent creates a Case linked to the Contact, you can trigger updates on the Contact when the Case is created:
trigger UpdateContactFromPostChat on Case (after insert) { Set<Id> contactIds = new Set<Id>(); // Collect Contact Ids from the newly created Cases for (Case c : Trigger.new) { if (c.ContactId != null) { contactIds.add(c.ContactId); } } // Fetch Contacts to update List<Contact> contactsToUpdate = [SELECT Id, Phone, MailingStreet FROM Contact WHERE Id IN :contactIds]; // Map Case fields (populated from post-chat form) to Contact fields for (Case c : Trigger.new) { for (Contact con : contactsToUpdate) { if (con.Id == c.ContactId) { // Update fields from post-chat data stored on the Case con.Phone = c.Post_Chat_Phone__c; // Replace with your custom Case field that stores post-chat input con.MailingStreet = c.Post_Chat_Street__c; break; } } } // Update the Contacts if (!contactsToUpdate.isEmpty()) { update contactsToUpdate; } }
Alternative: Use Record-Triggered Flow
If you prefer no-code, build a Record-Triggered Flow on the Case object (triggered after insert):
- Add a Get Records element to fetch the linked Contact
- Add an Update Records element to set the Contact fields using the Case's post-chat data fields
- Configure conditions to only run if the Contact exists (to avoid errors)
4. Test the Flow
Always test end-to-end to ensure it works:
- Log in as an existing Contact (or create a test Contact with a known email)
- Initiate a Live Agent chat, fill out the pre-chat form (make sure the email matches the test Contact)
- Complete the post-chat form with updated field values
- Check the Contact record in Salesforce to confirm the fields have been updated
- Verify the new Case is correctly linked to the Contact
Key Notes to Avoid Issues
- Ensure your Live Agent user profile has Edit permissions on the Contact object and the specific fields you're updating
- Use a unique matching field (like Email or Contact Id) to prevent updating the wrong Contact
- If you're using custom fields to store post-chat data on the Case, make sure those fields are mapped correctly from the post-chat form
内容的提问来源于stack exchange,提问作者niwesh binanshu

