I am trying to conditionally refresh my Case page depending on if the particular case has been updated or not. I use the below JavaScript and mark-up code to refresh my page
<apex:page controller="MyClass" showHeader="True" sidebar="false">
<apex:includeScript value="/support/console/36.0/integration.js"/>
<script type="text/javascript">
function RefreshPrimaryTab()
{
if (sforce.console.isInConsole())
sforce.console.getFocusedPrimaryTabId(showTabId);
else
window.top.location.href = '/' + id;
}
var showTabId = function showTabId(result)
{
debugger;
var tabId = result.id;
if ("{!IsModified}" == 'true') {
sforce.console.refreshPrimaryTabById(tabId , true);
}
};
</script>
<apex:form id="theForm">
<apex:pageBlock id="thePage">
<apex:outputPanel id="msgs">
<apex:pageMessages />
</apex:outputPanel>
<apex:pageBlockButtons location="bottom" >
<apex:commandButton value="Parent Case" action="{!processSelected}" oncomplete="RefreshPrimaryTab(); return false" rerender="msgs"/>
</apex:pageBlockButtons>...
And my apex controller is as follows
public with sharing class MyClass {
public List<string> isModified {get;set;}
...
public PageReference processSelected() {
String modified;
isModified=new List<String>();
try{
selectedCases = new List<String>();
for(getRelatedCases selCaseObj : relatedcases) {
if(selCaseObj.selected == true) {
selectedCases.add(selCaseObj.cid.CaseNumber);
String fields = 'parentid';
String curcaseid = ApexPages.currentPage().getParameters().get('Id');
Case curCase = [SELECT id FROM Case WHERE Id=:curcaseid];
curCase.put (fields, selCaseObj.cid.id);
update curCase;
modified='true';
}
}
}
catch(DmlException e){
modified='false';
ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.ERROR, e.getdmlMessage(0));
ApexPages.addMessage(msg);
//return NULL;
}
isModified.add((String) modified);
System.debug('Is updated?: ' + isModified);
return NULL;
}
...
So basically my method should either update a case and then JavaScript reload the page or throw the exception message without reloading the page.
Everything works fine if I simply run
sforce.console.refreshPrimaryTabById(tabId , true);
without checking if a case has been updated or not. But my page is getting reloaded every time along with the exception message. I need to avoid this.
I am new with SalesForce so any help will be highly appreciated.
public List isModified
{get;set;}?