How to refresh the parent tab from child tab in console app 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

Console App - Case to Case Asset record creation

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.

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

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

public PageReference backToObject(){
system.debug('caseassetId ='+caseassetId);
return new PageReference('/'+caseassetId);
}

 

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.

Reference : https://developer.salesforce.com/docs/atlas.en-us.api_console.meta/api_console/sforce_api_console_refreshprimarytabbyid.htm

 

Advertisements

One thought on “How to refresh the parent tab from child tab in console app salesforce

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s