You need to sign in to do that
Don't have an account?
Close VisualForce Page and Refresh Detail Record Page
I want to open a visualforce page from a custom button on a custom object detail page. The user selects a value in a tree dispayed in a VF page, and then clicks on a save button. I would like to update a record on the custom object, close the VF page, and then refresh the detail page so the record updates (updating the field itself would be better).
I've tried all kinds of solutions for similar situations on the web, but can't get any to work. Does someone know how to do this?
Thanks!
Here is VF:
<apex:page id="CompetencyRolesPage" StandardController="Competency__c" Extensions="TestPageController">
<apex:form >
<apex:outputPanel rendered="{!validRoleID}">
<c:TreeView selectable="true" roleOrUserId="{!RoleID}" value="{!selectedValues}" />
<apex:commandButton value="Save" action="{!saveRole}" />
</apex:outputPanel>
</apex:form>
</apex:page>
Here arerelevant pieces from controller:
public String selectedValues {get; set;}
public String userRoleID {get;set;}
public Boolean getValidRoleID() {
If(null==UserInfo.getUserRoleID())
return false;
else
return true;
}
public String getRoleID() {
userRoleId=UserInfo.getUserRoleID();
return userRoleID;
}
public PageReference saveRole() {
//will update customer field in detail record here.
return null;
}
The close script needs to be its own page, completely separate from the page that is the popup.
All Answers
Here's how I solved this in my project where we have a similar mechanism:
From there, you then only need to modify your TestPageController.cls:
By the way, you can simplify getValidRoleId:
This reduces the number of lines you have to cover with test methods, reducing both overall code size and test code size.
Thanks for your help. I tried as you suggested, but nothing happens when I click on the Save button. It looks like the VF page that gets refreshed and then stays open. I want the VF page to close, and the custom object detail page with the button to open the VF page refreshed. Here is the code with your suggestion.
In general, I'm trying to open a VF selection page to update a specific record wihin a custom object.
<apex:page id="CompetencyRolesPage" StandardController="Competency__c" Extensions="TestPageController">
<script language="JavaScript" type="text/javascript">
window.opener.top.location.reload();
window.close();
</script>
<apex:form >
<apex:outputPanel rendered="{!validRoleID}">
<c:TreeView selectable="true" roleOrUserId="{!RoleID}" value="{!selectedValues}" />
<apex:commandButton value="Save" action="{!saveRole}"/>
</apex:outputPanel>
</apex:form>
</apex:page>
Here is the controller:
public with sharing class TestPageController {
public String selectedValues {get; set;}
public String userRoleID {get;set;}
public PageReference saveRole() {
return page.CompetencyRolesPage;
}
public Boolean getValidRoleID() {
If(null==UserInfo.getUserRoleID())
return false;
else
return true;
}
public String getRoleID() {
userRoleId=UserInfo.getUserRoleID();
return userRoleID;
}
}
The close script needs to be its own page, completely separate from the page that is the popup.
Thank you for the great solution!