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;
}
}