1

I have a Service Cloud Console sidebar that I have a visualforce page embedded that runs 2 queries, and based on the results presents Alerts. One for cases, and one for account issues. My problem is that I can't get them to show independently. I have to have an open case for the Account alert to show. Also when the Alert query returns null I still see a blank red box. Any help would be appreciated.

Visualforce Page

<apex:includeScript value="/support/console/33.0/integration.js"/>
     <script type="text/javascript">
        function testOpenSubtab() {
            sforce.console.getEnclosingPrimaryTabId(openSubtab);
        }

        var openSubtab = function openSubtab(result) {            
            var primaryTabId = result.id;
           sforce.console.openSubtab(result.id,'/'+'{!alertCase.Id}',false,'{!alertCase.CaseNumber}',null);            
            sforce.console.focusNavigationTab();

        };

        var openSuccess = function openSuccess(result) {

            if (result.success == true) {
                alert('subtab successfully opened');
            } else {
                alert('subtab cannot be opened');
            }
        };

    </script>

    <style> 
    .EMFDiv{
        display:none;
    }
    .ShowEMFYes { 
        display:block !important; 
    } 
    </style>
    <div class="EMFDiv ShowEMF{!EMFStatus}" >
    <apex:pageMessage id="EMFmessage" summary="{!ShowMessage.Message__c}" severity="error" strength="1"/>

    </div>
    <apex:pageMessages escape="false"/>

</apex:page>

Controller

public class AccountCaseExtension {

    private final Account acct;
    public Case alertCase {get;set;}
    boolean showCaseAlert = false;
    boolean showAccountAlert = false;
    String severity;
    public Account alertAccount {get; set;}
    public Account EMFStatusAccount {get;set;}
    //public Boolean EMFIssue = false;
    public Alert__c ShowMessage {get; set;}
    public String message = '';
    public String EMFStatus = '';

    public String getSeverity() {
        return severity;
    }


    public AccountCaseExtension(ApexPages.StandardController stdController) {
        this.acct = (Account)stdController.getRecord();  

        String alertString;

        try {
            alertCase = [Select Id, AccountId, Subject, Origin, CreatedDate, CaseNumber, IsClosed, LastViewedDate, Priority from Case where AccountId = :acct.Id and CreatedDate = LAST_N_DAYS:7  and IsClosed = False /*and Origin = 'Compass'*/ order by CreatedDate ASC LIMIT 1];
                        showCaseAlert = true;
            alertString = 'A case was generated by ' + alertCase.Origin+' with the following subject: <a href="#" target="_blank" onClick="testOpenSubtab();return false;">'+alertCase.Subject+'</a>';
            System.Debug('Alert String: ' + alertString);
            if(alertCase.Priority == 'Low') {
                ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO,alertString));    
            }
            else if(alertCase.Priority == 'Medium') {
                ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.WARNING,alertString));
            }
            else if(alertCase.Priority == 'High') {       
                System.Debug('high');     
                ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,alertString));
            }
            } catch(Exception e) {
                System.debug('Thrown Exception: '+ e);
        }
        try{
            EMFStatusAccount = [SELECT Id, Name, EMF_Status__c, EMF_Issue__c FROM Account WHERE id = :acct.Id LIMIT 1];
            EMFStatus = EMFStatusAccount.EMF_Status__c;//This gets a Yes/No from the above query.
            ShowMessage = [SELECT Id, Name, Message__c FROM Alert__c WHERE Alert_Start__c = TODAY ORDER BY Alert_Start__c DESC LIMIT 1];
            message = ShowMessage.Message__c;//Figure out how to handle the null pointer in the above query.
            showAccountAlert = true;
        }catch(QueryException qe) {
            showAccountAlert = false;
            System.debug('EMF Alert Query returned no rows' + qe);
        }    
    }

    public String getGreeting() {
        return 'Hello ' + acct.name + ' (' + acct.id + ')';
    }
    public boolean getShowCaseAlert() {
        return showCaseAlert;
    }
    public boolean getShowAccountAlert() {
        return showAccountAlert;
    }

    public String getEMFStatus () {
        return EMFStatus;
    }
    public String getShowMessage () {
        return message;
    }
}

1 Answer 1

0

After painstakingly going over the code I finally have this figured out. So I figured I would share this for anyone else who might want to show alerts in the Service Cloud Console. As I found no information about creating this functionality.

I inherited this code from the implementors so I assumed it was all necessary. I found out that I didn't need anything in the visualforce page except the tags and the tag. This was put into a Custom Console Component left sidebar. Here is the code:

Visualforce Page

<apex:page standardController="Account" extensions="AccountCaseExtension" showHeader="false" sidebar="false" rendered = "{!showAlert}">
    <apex:pageMessages escape="false"/>        
</apex:page>

Controller

public class AccountCaseExtension {

    private final Account acct;
    public Case alertCase {get;set;}
    boolean showAlert = false;
    String severity;
    public Account alertAccount {get; set;}
    public Account EMFStatusAccount {get;set;}
    public Alert__c ShowMessage {get; set;}
    public String EMFStatus = '';

    public String getSeverity() {
        return severity;
    }

    public AccountCaseExtension(ApexPages.StandardController stdController) {
        this.acct = (Account)stdController.getRecord();  

        String alertString;
        // This is where the case alerts are generated.
        try {
            alertCase = [Select Id, AccountId, Subject, Origin, CreatedDate, CaseNumber, IsClosed, LastViewedDate, Priority from Case where AccountId = :acct.Id and CreatedDate = LAST_N_DAYS:7  and IsClosed = False /*and Origin = 'Compass'*/ order by CreatedDate ASC LIMIT 1];
            showAlert = true;
            alertString = 'A case was generated by ' + alertCase.Origin+' with the following subject: <a href="#" target="_blank" onClick="testOpenSubtab();return false;">'+alertCase.Subject+'</a>';
            System.Debug('Alert String: ' + alertString);
            if(alertCase.Priority == 'Low') {
                ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO,alertString));    
            }
            else if(alertCase.Priority == 'Medium') {
                ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.WARNING,alertString));
            }
            else if(alertCase.Priority == 'High') {       
                System.Debug('high');     
                ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,alertString));
            }
        } catch(Exception e) {
                System.debug('Thrown Exception: '+ e);
        }
        // This is where the EMF Alerts are generated.
        try{
            EMFStatusAccount = [SELECT Id, Name, EMF_Status__c, EMF_Issue__c FROM Account WHERE id = :acct.Id LIMIT 1];
            EMFStatus = EMFStatusAccount.EMF_Status__c;//This gets a Yes/No from the above query.
            System.debug('Emf Status: ' + EMFStatus);
            // Next line throws exception if query returns Null
            ShowMessage = [SELECT Id, Name, Message__c FROM Alert__c /*WHERE Alert_Start__c = TODAY*/ ORDER BY Alert_Start__c DESC LIMIT 1];
            if(ShowMessage.Message__c != null && EMFStatus == 'Yes') {
                ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,ShowMessage.Message__c));    
            }

            showAlert = true;
        }catch(QueryException qe) {
            showAlert = false;
            EMFStatus = 'No';
            System.debug('EMF Alert Query returned no rows' + qe);
        }
    }
    public boolean getShowAlert() {
        return showAlert;
    }
    public String getEMFStatus () {
        return EMFStatus;
    }
}

I hope this helps someone in the future. Happy coding.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .