You need to sign in to do that
Don't have an account?
bouscal
Refresh Parent Window from Popup
Have a button that calls a VF page for a user to fill in 3 required fields then create a case.
The VF page is in a pop up window.
When the Case is created I want the parent window to redirect to the newly created Case.
button on Contact page passes accountid and contactid in URL
Field Set is used to populate the fields in the page.
Everything works except closing the pop-up and redirecting the parent window.
Apex Page:
<apex:page standardController="Case" extensions="CreateCaseController" showHeader="false"> <apex:form > <apex:pageMessages /> <apex:pageBlock title="New Case"> <apex:pageBlockButtons > <apex:commandButton value="Save" action="{!Save}"/> <input type="button" value="Cancel" class="btn" onclick="window.close();"/> </apex:pageBlockButtons> <apex:outputLabel value="Account: " for="acc"/ > <apex:outputField id="acc" value="{!case.accountid}" /><br/> <apex:outputLabel value="Contact: " for="con"/> <apex:outputField id="con" value="{!case.contactid}" /> <apex:pageBlockTable value="{!$ObjectType.Case.FieldSets.CaseQuickCreate}" var="f"> <apex:outputField value="{!case.contactid}"/> <apex:outputField value="{!case.accountid}"/> <apex:column value="{!f.Label}"> <apex:facet name="header"></apex:facet> </apex:column> <apex:column > <apex:inputField value="{!Case[f]}" required="{!f.Required}" /> </apex:column> </apex:pageBlockTable> </apex:pageBlock> <script type="text/javascript"> if ({!isSaveSuccess}) { var url = '/{!cs.id}'; opener.location.href=url; window.close(); } </script> </apex:form> </apex:page>
Extension:
/** Create Case controller used by support for Quick Case creation TBouscal 2013-11-25 */ public class CreateCaseController{ public Account account{get; set;} public Contact contact{get; set;} public Case cs{get; set;} public Boolean isSaveSuccess{get; set;} Public string retURL{get; set;} public CreateCaseController(ApexPages.StandardController controller){ cs=((case) controller.getRecord()); cs.contactid=ApexPages.currentPage().getParameters().get('cid'); cs.accountid=ApexPages.currentPage().getParameters().get('aid'); } public void createCase(){ cs.contactid=ApexPages.currentPage().getParameters().get('cid'); cs.accountid=ApexPages.currentPage().getParameters().get('aid'); insert cs; isSaveSuccess = true; retUrl=cs.id; }
Here is a good resource on this:
http://www.valnavjo.com/blog/modal-dialog-on-a-standard-salesforce-page/
All Answers
Try assigning the open window to a variable in the button's javascript code. This will allow you to access variables from the opened window as well as check when it closes. Ex.
//Open button Javascript
var caseWindow;
caseWindow = open("/apex/<<YourVFPageName>>", "New Case", "height=500, width=300");
var timer = setInterval(checkWindow, 500);
function checkWindow() {
if (caseWindow.case_id) {
var id = caseWindow.case_id;
clearInterval(timer);
caseWindow.close();
window.location.href = '/'+ id;
}
}
//Javascript in VF Page
<script type="text/javascript">
var case_id;
if ({!isSaveSuccess}) {
case_id = '{!cs.id}';
}
</script>
The "Save" button has no javascript code, it's an <apex:commandButton>.
Here is a good resource on this:
http://www.valnavjo.com/blog/modal-dialog-on-a-standard-salesforce-page/
Yes,
If you are using a visualforce page use:
If you are using a javascript button on a page layout go to the resource page and click the view link. This will open a new window or tab with the resource. Copy the url pass the .com and paste it to the requiredscript paran. Ex: