Standard Messaging Session Transfer feature is not currently available in Salesforce.
Vote for the following idea for the standard Messaging Session Transfer feature in Salesforce.
https://ideas.salesforce.com/s/idea/a0B8W00000GdmJtUAJ/messaging-agent-transfers
If the above Standard Feature is delivered, go with the Standard instead of the following custom Transfer Feature for easier maintenance.
The following implementation is not standard and it is purely customisation.
1. Create a Custom object.
2. Create Custom Fields in the custom object created in step 1. I have created three lookup fields for Messaging Session, Messaging User and User.
3. Create the Service Channel for the custom object.
4. Create the following apex class.
public class TransferMessagingSessionController {
@AuraEnabled
public static String fetchMEU( String messagingSessionId ) {
return [
SELECT MessagingEndUserId
FROM MessagingSession
WHERE Id =: messagingSessionId
][ 0 ].MessagingEndUserId;
}
}
5. Create the following Lightning Aura Component.
Component:
<aura:component implements="force:lightningQuickAction,force:hasRecordId"
access="global"
controller="TransferMessagingSessionController">
<aura:attribute name="MEUId" type="String"/>
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
<lightning:omniToolkitAPI aura:id="omniToolkit" />
<lightning:recordEditForm objectApiName="Messaging_Session_Transfer__c"
onsubmit="{!c.handleSubmit}"
aura:id="recordEditForm">
<lightning:messages />
<lightning:inputField fieldName="Messaging_Session__c"
value="{!v.recordId}" disabled="true"/>
<lightning:inputField fieldName="Messaging_User__c"
value="{!v.MEUId}" disabled="true"/>
<lightning:inputField fieldName="User__c" />
<lightning:button type="submit" name="Submit"
label="Transfer" class="slds-m-top_medium"/>
</lightning:recordEditForm>
</aura:component>
JavaScript:
( {
doInit: function( component, event, helper ) {
console.log( 'Inside Init Method' );
let action = component.get( "c.fetchMEU" );
action.setParams( {
"messagingSessionId": component.get( "v.recordId" )
} );
action.setCallback( this, function( response ) {
let state = response.getState();
if (state === "SUCCESS") {
component.set( "v.MEUId", response.getReturnValue() );
}
} );
$A.enqueueAction( action );
},
handleSubmit: function ( component, event, helper ) {
console.log( 'Inside Submit' );
event.preventDefault();
let omniAPI = component.find( "omniToolkit" );
omniAPI.getAgentWorks().then( function( result ) {
console.log( 'Inside Omni API' );
let works = JSON.parse( result.works );
let work = works[ 0 ];
if ( work && work.hasOwnProperty( 'workId' ) ) {
console.log( 'Inside with Work Id' );
omniAPI.closeAgentWork( { workId: work.workId } )
.then( function( res ) {
if ( res ) {
console.log( "Closed work successfully" );
} else {
console.log( "Close work failed" );
}
} ).catch( function( error ) {
console.log( 'Error occured when closing is', JSON.stringify( error ) );
} );
}
} );
const fields = event.getParam( 'fields' );
console.log( 'Fields are ' + JSON.stringify( fields ) );
component.find( 'recordEditForm' ).submit( fields );
let showToast = $A.get( "e.force:showToast" );
showToast.setParams( {
title : 'Transfer Completed',
message : 'Record Transferred Sucessfully.' ,
type : 'success',
mode : 'dismissible'
} );
showToast.fire();
$A.get( "e.force:closeQuickAction" ).fire();
$A.get( "e.force:refreshView" ).fire();
}
} )
6. Create a Quick Action on the Messaging Session.
7. Add the Quick Action to the page layout.
8. Create an Omni-Flow for routing Messaging Session Transfer record.
9. Create a Record Triggered Flow for Messaging Session Transfer Object.
Output:
Agents who received the custom object records can select the Messaging User and use “Start Conversation” standard quick action to converse with the end users.
Video Reference: