본문 바로가기

개발자정보

Salesforce의 하위 탭에서 상위 탭을 새로 고치는 방법

반응형

Scenario 

Consider a scenario where we need to create a related object record of standard Case object, using the new button in the related list. For example, Case Asset is one of the related objects of the case object and its new button action is overridden with a custom page.

 

The save action defined in the custom page routed us into the newly created case asset record page, after the successful record creation. But the parent Case tab will not automatically reflect this record creation and will require us going back to the Case tab and performing a manual refresh.Instead, can we refresh this from the child Case Asset tab itself?

Details

The image shows the parent case tab and it’s child tabs. External Page is the custom page which was opened from the details page in a new tab.

 

 

Solution

Step 1

The oncomplete event of the record save button should call a js method like below.
<apex:commandbutton action="{!saveAsset}" oncomplete="doneComplete();"/>

Step 2

Define the javascript  function doneComplete.

[sourcecode language=”javascript”]
function doneComplete(){
//Check if the page opened in console application
if(sforce.console.isInConsole()){
sforce.console.getFocusedPrimaryTabId(showTabId);
}
redirectToObjectDetail();
}
function refreshSuccess(result) {

}
function showTabId(result) {
//Display the tab ID
sforce.console.refreshPrimaryTabById(result.id, true, refreshSuccess);
}
[/sourcecode]

sforce.console.isInConsole() – responds when its invocation happens in the console app.

sforce.console.getFocusedPrimaryTabId()  – console method provides the id of the primary tab which is currently active. showTabId is a callback which receives the parent tab id and calls the refresh console method.

sforce.console.refreshPrimaryTabById() – A console javascript function, to refresh the parent tab and the child components.

refreshSuccess – handler for a successful refresh.

Step 3 :

redirectToObjectDetail() – an action function which calls the server action and redirects to the object detail page.

<apex:actionFunction name=”redirectToObjectDetail” action=”{!backToObject}”/>

backToObject – action redirects to a page reference

[sourcecode language=”java”]
public PageReference backToObject(){
system.debug(‘caseassetId =’+caseassetId);
return new PageReference(‘/’+caseassetId);
}
[/sourcecode]

 

Conclusion

The parent id fetched from the currently active primary tab is passed into the refresh console method provided by Salesforce. Then it refreshes the parent and child tabs. Please refer the below link to get the details of the console methods and leave a comment if you have any doubts.

 

refreshPrimaryTabById()

Refreshes a primary tab specified by ID, including its subtabs. This method can't refresh subtabs with URLs to external pages or Visualforce pages. This method is only available in API version 22.0 or later.

Syntax

 
 
 
sforce.console.refreshPrimaryTabById(id:String, activate:Boolean, (optional)callback:Function, (optional)fullRefresh:Boolean)

Arguments

NameTypeDescription
id string ID of the primary tab to refresh.
activate boolean If true, the refreshed primary tab displays immediately. If false, the refreshed primary tab displays in the background.
callback function JavaScript method that’s called upon completion of the method.
fullRefresh boolean Enables a full refresh of the entire case feed.

Sample Code–Visualforce

<apex:page standardController="Case">

     <A HREF="#" onClick="testRefreshPrimaryTabById();return false">
         Click here to refresh a primary tab by id</A> 

    <apex:includeScript value="/support/console/54.0/integration.js"/>
    <script type="text/javascript">
        function testRefreshPrimaryTabById() {
            //Get the value for 'scc-pt-0' from the openPrimaryTab method
            //This value is for example purposes only
            var primaryTabId = 'scc-pt-0';
            sforce.console.refreshPrimaryTabById(primaryTabId, true, refreshSuccess);
        }
        
        var refreshSuccess = function refreshSuccess(result) {
            //Report whether refreshing the primary tab was successful
            if (result.success == true) {
                alert('Primary tab refreshed successfully');
            } else {
                alert('Primary did not refresh');
            }
        };
        
  </script>

</apex:page>
 

Note

To see this example in action, click the custom link on a case. For more information, see Define Custom Buttons and Links in the Salesforce help.

Response

This method is asynchronous, so it returns its response in an object in a callback method. The response object contains the following field:

NameTypeDescription
success boolean true if the primary tab refreshed successfully; false if the primary tab didn't refresh.
반응형