Editing Custom Interaction Logs

Available in: Salesforce Classic

This is part of Developing with the Service Cloud.

You can find out more on how to use this Visualforce page here. Please note, this is code is not supported by salesforce.com and may be subject to change in the future.

Apex Code

public class CustomInteractionLog {

    public String caseId { 
        get {
            if(caseId == null) {
                caseId = ApexPages.currentPage().getParameters().get('id');
            }
            return caseId;
        }
        set; 
    }

    public void updateWhoWhatId() {
        Integer caseCount = [Select COUNT() from Case where id = :caseId];
        if (caseCount==0) {
            statusMessage = 'This log is not associated with a Case or Contact! Please save the case.';
            return;
        }
        Case myCase = [Select id, contactId from Case where id = :caseId];
        task.whoId = myCase.contactId;
        task.whatId = myCase.id;
    }

    private void initializeTask() {
        updateWhoWhatId();
        task.subject = Subject;
    }
    
    private String Subject { 
        get {
            Subject = 'Call at ' + DateTime.now();
            return Subject;
        }
        set; 
    }

    public CustomInteractionLog(ApexPages.StandardController controller) {
        initializeTask();
    }       

    public String ANI { get; set;}
    public String CallObject { get; set;} 
    public Integer CallDurationInSeconds { get; set;} 
    public String CallType { get; set;}  
    public String CallDisposition { get; set;}        
    
    public String statusMessage { get; set; }

    public Task task { 
        get {
            if(task == null) {
                task = new Task();
            }
            return task;
        }
        set; 
    }
    
    public void setCallAttachedData() {
        task.CallObject = CallObject;
        //task.ANI__c = ANI;
    }     

    public void setCallEndData() {
        task.CallDurationInSeconds = CallDurationInSeconds;
        task.CallDisposition = CallDisposition;    
        save();
    }
    
    public void save() {
        upsert task;
        statusMessage = 'Last save at ' + DateTime.now();
    }
    
     public void saveAndNew() {
        save();
        task = null;
        initializeTask();
        //task.ANI__c= ANI;
        task.CallObject = CallObject;
    }        
}


Visualforce Code

<apex:page standardController="Case" extensions="CustomInteractionLog" tabStyle="Task">    
    <apex:includeScript value="/support/console/24.0/integration.js"/>
    <script type="text/javascript">
        
        var callObjectId = null;
        
        var onFocusedSubtabCallback = function (result) {
            var entityId = result.objectId;
            if (entityId.substr(0,3) === '500') {
                updateWhoWhatIdJS(result.objectId);
            }
        };  
        sforce.console.onFocusedSubtab(onFocusedSubtabCallback);

        var getCallAttachedDataCallback = function (result) {            
            setCallAttachedDataJS(callObjectId, JSON.parse(result.data).ANI);
        };
    
        /* Retrieving call id of first call that came in and
        * calling getCallAttachedData() to retrieve call data.
        * Note that we are using the cti submodule here
        */                  
        var getCallObjectIdsCallback = function (result) {        
            if (result.ids !== 'null') {       
                var ids = result.ids.split(',');        
                if (ids.length > 0) {   
                    callObjectId = ids[0];     
                    sforce.console.cti.getCallAttachedData(callObjectId, getCallAttachedDataCallback);        
                }        
            }        
        };
        sforce.console.cti.getCallObjectIds(getCallObjectIdsCallback);
                       
        var onCallBeginCallback = function (result) {
            callObjectId = result.id;
            sforce.console.cti.getCallAttachedData(result.id, getCallAttachedDataCallback);
        };
        sforce.console.cti.onCallBegin(onCallBeginCallback);

        var onCallEndCallback = function (result) {
            setCallEndDataJS(result.duration, result.disposition);
        };
        sforce.console.cti.onCallEnd(onCallEndCallback);
        
    </script>
    <apex:form >
        <apex:pageBlock title="Log A Call" id="thePageBlock" mode="edit">
            <apex:pageMessages />
            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!save}" reRender="updateable, relatedList"/>
                <apex:commandButton value="Save And New" action="{!saveAndNew}" reRender="updateable, relatedList"/>
            </apex:pageBlockButtons>
            <apex:actionFunction action="{!updateWhoWhatId}" name="updateWhoWhatIdJS" reRender="updateable">
                <apex:param name="newCaseId" assignTo="{!caseId}" value=""/>
            </apex:actionFunction>               
            <apex:actionFunction action="{!setCallAttachedData}" name="setCallAttachedDataJS" reRender="updateable">
                <apex:param name="CallObject" assignTo="{!CallObject}" value=""/>
                <apex:param name="ANI" assignTo="{!ANI}" value=""/>
            </apex:actionFunction>
            <apex:actionFunction action="{!setCallEndData}" name="setCallEndDataJS" reRender="updateable, relatedList">
                <apex:param name="CallDuration" assignTo="{!CallDurationInSeconds}" value=""/>
                <apex:param name="CallDisposition" assignTo="{!CallDisposition}" value=""/>
            </apex:actionFunction>            
            <apex:outputPanel id="updateable">
                 <apex:pageBlockSection columns="1">
                    <apex:inputField value="{!task.whoId}"/>                        
                    <apex:inputField value="{!task.whatId}"/>
                    <apex:inputField style="width:230px;" value="{!task.subject}"/>                    
                    <!-- <apex:inputField value="{!task.ANI__c}"/> -->                    
                </apex:pageBlockSection>
                <apex:pageBlockSection columns="1">
                    <apex:inputField style="height:100px;width:350px;" value="{!task.description}"/>                                        
                    <br/><apex:outputText value="{!statusMessage}" />                                       
                </apex:pageBlockSection>
            </apex:outputPanel>            
        </apex:pageBlock>
    </apex:form>
    <apex:outputPanel id="relatedList">
        <apex:relatedList list="OpenActivities"/>
    </apex:outputPanel>
</apex:page>