Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.
Integrate the Engagement Objects Into Your CTI System
Modifications to the CTI Adapter
1<button class="slds-size--1-of-2 slds-button slds-button--brand"
2onclick="{!c.accept}">Accept</button>1accept : function(cmp, event, helper) {
2helper.renderConnectedPanel(cmp);
3},1renderConnectedPanel : function(cmp){
2 var recordId = cmp.get('v.recordId');
3 var account = cmp.get('v.account');
4 var recparam=(recordId)?recordId:'UNKNOWN';
5 sforce.opencti.runApex({
6 apexClass : 'SoftphoneContactSearchController',
7 methodName : 'createEngagementInteraction',
8 methodParams : 'recordId='+recparam ,
9 callback : function(result) {
10 cmp.getEvent('editPanel').setParams({
11 label : 'Open CTI Softphone: ' + cmp.get('v.state')
12 }).fire();
13 if (result.success) {
14 sforce.opencti.screenPop({
15 type : sforce.opencti.SCREENPOP_TYPE.SOBJECT,
16 params : { recordId : result.returnValue.runApex }
17 });
18 } else {
19 throw new Error('Unable to make a call. Contact your admin.');
20 }
21 cmp.getEvent('renderPanel').setParams({
22 type : 'c:connectedPanel',
23 attributes : {
24 showDialPad : false,
25 recordId : recordId,
26 engagementId : result.returnValue.runApex,
27 callType : 'Inbound',
28 account : account,
29 recordName: cmp.get('v.recordName'),
30 presence : cmp.get('v.presence')
31 }
32 }).fire();
33 }
34 });
35}1// Create Engagement Interaction using connect API
2webService static String createEngagementInteraction(String recordId) {
3 system.debug('In create Engagement Interaction');
4 ConnectApi.EngagementInteractionCreateInput interactionInput = new
5ConnectApi.EngagementInteractionCreateInput();
6 interactionInput.communicationChannel = 'Voice Call';
7 interactionInput.attendeeVerified = false;
8 interactionInput.startDateTime =
9datetime.now().formatGMT('yyyy-MM-dd\'T\'HH:mm:ss.SSS\'Z\'');
10 interactionInput.status = 'New';
11 if(recordId !='UNKNOWN' ){
12 interactionInput.initiatingAttendeeId = recordId;
13 interactionInput.attendeeAuthenticated = true;
14 }
15 ConnectApi.EngagementsCreateInput containerInput = new
16ConnectApi.EngagementsCreateInput();
17 containerInput.engagementInteraction = interactionInput;
18 ConnectApi.EngagementsCreateOutput output =
19ConnectApi.EngagementContainerConnect.createEngagementInteraction(containerInput);
20 return output.engagementInteraction.id;
21}1List<ConnectApi.EngagementAttendeeCreateInput> eaList = new
2List<ConnectApi.EngagementAttendeeCreateInput>();
3ConnectApi.EngagementAttendeeCreateInput internalAttendeeInput = new
4ConnectApi.EngagementAttendeeCreateInput();
5internalAttendeeInput.startDateTime =
6datetime.now().formatGMT('yyyy-MM-dd\'T\'HH:mm:ss.SSS\'Z\'');
7internalAttendeeInput.internalAttendeeId = UserInfo.getUserId();
8eaList.add(internalAttendeeInput);
9if(recordId !='UNKNOWN' ){
10 ConnectApi.EngagementAttendeeCreateInput externalAttendeeInput = new
11ConnectApi.EngagementAttendeeCreateInput();
12 externalAttendeeInput.startDateTime =
13datetime.now().formatGMT('yyyy-MM-dd\'T\'HH:mm:ss.SSS\'Z\'');
14 externalAttendeeInput.externalAttendeeId = recordId;
15 eaList.add(externalAttendeeInput);
16}
17interactionInput.engagementAttendees = eaList;Engagement attendee records for internal attendees of an engagement are automatically created after an engagement interaction record is created. If necessary, stop the automatic creation of engagement attendee records by turning off the Auto-Creation of Internal Attendee Record org preference.
1<button aura:id="endcall" class="slds-size--1-of-2 slds-button slds-button--destructive" onclick="{!c.endCall}">End</button>1endCall: function(cmp, event, helper) {
2sforce.opencti.runApex({
3apexClass : 'SoftphoneContactSearchController',
4methodName : 'updateEngagementInteraction',
5methodParams : 'recordId=' + cmp.get('v.engagementId'),
6callback : function(result) {
7if (result.success) {
8} else {
9throw new Error(
10'Unable to update EI. Contact your admin.');
11}
12helper.logCall(cmp, function(response) {
13cmp.getEvent('renderPanel').setParams({
14type : 'c:phonePanel',
15toast : {'type': 'normal', 'message': 'Call was ended.'},
16attributes : { presence : cmp.get('v.presence')}
17}).fire();
18})
19var param = {callback:
20function(response) {
21if (response.success) {
22console.log('API method call executed successfully! returnValue:', response.returnValue);
23} else {
24console.error('Something went wrong! Errors:', response.errors);
25}
26}};
27sforce.opencti.refreshView(param);
28}
29});
30}If necessary, add methods to update engagement interaction, engagement attendee, and engagement topic records to the SoftphoneContactSearchController Apex class.
1//Create Engagement Attendee
2List<EngagementAttendee> eaList = new List<EngagementAttendee>();
3EngagementAttendee internalAttendeeInput = new EngagementAttendee();
4internalAttendeeInput.EngagementId = output.engagementInteraction.id;
5internalAttendeeInput.StartDateTime = datetime.now();
63
7Integrate Your CTI System with the Engagement Objects
8internalAttendeeInput.InternalAttendeeId = UserInfo.getUserId();
9eaList.add(internalAttendeeInput);
10insert eaList;
11System.debug('EI Created'+eaList.get(0).id);
12//Update Engagement Attendee
13EngagementAttendee internalAttendee=[select id from EngagementAttendee where
14EngagementId=:output.engagementInteraction.id];
15internalAttendee.EndDateTime = datetime.now();
16internalAttendee.IsVerified = true;
17internalAttendee.Role='Self';
18update internalAttendee;
19System.debug('EA updated'+internalAttendee.EndDateTime);
20//Create Engagement Topic
21List<EngagementTopic> topicList = new List<EngagementTopic>();
22EngagementTopic topic = new EngagementTopic();
23topic.EngagementId = output.engagementInteraction.id;
24topic.Name = 'Address Change';
25topicList.add(topic);
26insert topicList;
27System.debug('ET Created'+topicList.get(0).id);
28//Update Engagement Topic
29EngagementTopic engagementTopic = [select id from EngagementTopic where
30EngagementId=:output.engagementInteraction.id];
31engagementTopic.ProcessFailureReason = 'Job Shift';
32update engagementTopic;