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()
Syntax
sforce.console.refreshPrimaryTabById(id:String, activate:Boolean, (optional)callback:Function, (optional)fullRefresh:Boolean)
Arguments
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:
success | boolean | true if the primary tab refreshed successfully; false if the primary tab didn't refresh. |
'개발자정보' 카테고리의 다른 글
Age Of ‘Dock’ing (0) | 2022.04.16 |
---|---|
Salesforce(세일즈포스) Quick Action Modal Popup Component 스타일 수정 방법 (0) | 2022.04.16 |
Salesforce(세일즈포스) Action Function (0) | 2022.04.16 |
Salesforce(세일즈포스) Current Geolocation Component (0) | 2022.04.16 |
Salesforce(세일즈포스) NullPointerException 방지를 위한 안전한 방법, Safe Navigation Operator (0) | 2022.04.16 |