function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Kelly KKelly K 

refresh issue in console

Hi All,

I have a very frustrating refresh issue that I've been trying to figure out and I've gotten nowhere.

Essentially, I'm coding for the service cloud console where my components are custom visualforce pages leveraging the standard controller with a custom extension to handle custom actions and page redirects.

Ideally, if the user saves the record, the entire record should refresh. This is accomplished with javascript pretty easily - I just have to specify in my apex code that the pageRefrence returns null to ensure the javascript gets invoked.

However, the problem is if the record isn't successfully saved, then I need an error message to display. If I let the javascript refresh the page, then it the error message is not displayed and the whole thing refreshes and wipes out any information the user may have typed (making it look like a successful save to boot). If I set the returned pageReference to CurrnentPage(), then the error will not display unless I remove the javascript function out of the apex:commandButton tag - but then I don't get the refreshes on a successful save.

How do I get my javascript and apex to play nicely? I tried using a boolean variable to tell the javascript to run, but it seems that even if I tell it not to refresh, just the javascript running removes the error message from displaying on the page. I also tried saving the error message to a public variable to see if I could let it refresh anyways, but shortly scratched that idea after realizing there was no way to reset the user's values. Here's where I left off at...

Any suggestions might bring back some of my sanity on this topic.

Here's my visualforce page:
<apex:page standardController="Account" extensions="FC_AccountExtension">

    <style type="text/css">
        .bPageBlock .detailList .labelCol {
            width: 4%;
        }
    </style>

    <apex:sectionHeader title="Task" subtitle="New Task" />
 
    <apex:form >
    <apex:pageBlock title="Task Edit" mode="Edit">
        <apex:pageBlockButtons location="top">
            <apex:commandButton action="{!saveTask}" oncomplete="doRefreshPage({!refreshConsole}); return false;" value="Save" id="save"/>
            <!--oncomplete="doRefreshPage(); return false;"  oncomplete="doRefreshPage({!refreshConsole}); return false;" -->
            <apex:commandButton action="{!cancelTask}" value="Cancel" immediate="true"/>
        </apex:pageBlockButtons>
        
        <br/><br/>
        <apex:pageMessages />
        <apex:pageMessage severity="ERROR" summary="{!errorMessage}" rendered="{!errorMessage != null}" strength="3" />        
        <apex:pageBlockSection title="Task Information" columns="2">
            <apex:pageBlockSection columns="1" showHeader="false">
                <apex:inputField value="{!task.OwnerId}" required="true"/>
                <apex:inputField value="{!task.Subject}" required="true"/>
                <apex:inputfield value="{!task.ActivityDate}"/>
                <apex:inputField value="{!task.Priority}" required="true"/>
                <apex:inputField value="{!task.Demo__c}"/>
                <apex:inputField value="{!task.Pre_Call__c}"/>
                <apex:inputField value="{!task.Call_attempted_no_message_left__c}"/>
                <apex:inputField value="{!task.Prospecting_call_connected__c}"/>
                <apex:inputField value="{!task.Prospecting_call_left_message__c}"/>
                <apex:inputField value="{!task.Prospecting_call_affirmative__c}"/>
                <apex:inputField value="{!task.Add_to_Campaign__c}"/>
                <apex:inputField value="{!task.Promotion_Campaign__c}"/>
                <apex:inputField value="{!task.Billable_Docs__c}"/>                                                                                                                                                
            </apex:pageBlockSection>
            <apex:pageBlockSection columns="1" showHeader="false">
                <apex:inputField value="{!task.Status}"/>
                <apex:inputField value="{!task.Type}"/>
                <apex:inputField value="{!task.WhoId}"/>
                <apex:inputField value="{!task.WhatId}"/>
                <apex:inputField value="{!task.Promo__c}"/>
                <apex:inputField value="{!task.No_Promo__c}"/>
                <apex:inputField value="{!task.On_site_call_connected__c}"/>
                <apex:inputField value="{!task.On_site_call_dropped_lit__c}" label="On site call, dropped it?"/>
                <apex:inputField value="{!task.Unknown_PM_System_Call__c}"/>
            </apex:pageBlockSection>            
        </apex:pageBlockSection>     
        <apex:pageBlockSection columns="1" title="Additional Comments">
            <apex:inputField value="{!task.Description}" style="width:98%;"/>
        </apex:pageBlockSection>   
    </apex:pageBlock>
    </apex:form>

    <apex:includeScript value="/support/console/31.0/integration.js"/>    
    <script type='text/javascript'>
        //This function allows the user to press enter to search
        var refreshPrimaryTab = function showTabId(result) {
            var tabId = result.id;
            sforce.console.refreshPrimaryTabById(tabId, true);
        }
        function doRefreshPage(refreshConsole) {
            if(refreshConsole == true)
                sforce.console.getEnclosingPrimaryTabId(refreshPrimaryTab);
        }
    </script>      
</apex:page>

And the part of the controller that's relevant:
public pageReference saveTask() {
        PageReference pageRef = null;
        refreshConsole = false;
        
        try {
            //upsert for updating/inserting new contact
            upsert task;
            
            //Allow the javascript to refresh the page
            refreshConsole = true;

            //clear the task for next action
            //pageRef = new PageReference('/apex/SCC_Task_Related_List?id=' + task.WhatId);
            //pageRef.setRedirect(true);
            task = null;
        }
        catch(system.DMLException e) {
            //ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, e.getDmlMessage(0)));
            errorMessage = e.getDMLMessage(0);
            pageRef = ApexPages.CurrentPage();
        }
        
        //Do not need to set a page redirect here otherwise it overrides the javascript to refresh            
        return pageRef;
    }


Chris GaryChris Gary
Hey Kelly!

Its Chris here from EnablePath - hope all is well.  Here is a possible solution.  Why not just pass in the Console Tab URL you need to refresh to the controller?  In the controller, you can determine whether to pass back a null page reference, or pass back the URL passed in a the reference? You can get the tab url using the sforce.console.getTabLink method. Once you do that, you can gt rid of the 'oncomplete' all together.  Let me know what you think.