+ Start a Discussion
Jean Grey 10Jean Grey 10 

Rerender original page after creating record

I have a vf page with extension that creates some records on a custom object related to OpportunityLineItem. I need the page to close after the records are created, and then refresh the original OLI page to show the new record in the related list. I tried this but it doesn't refresh the page:

    <apex:page standardController="OpportunityLineItem" extensions="ScheduleExtension" docType="html-5.0">
    <apex:form>
<apex:actionFunction name="Rerender()" rerender="true" />
    <script> function Return() { 
        window.close();
        Rerender();
    } 
    </script>
        <apex:pageBlock  title="Set Product Schedule for {!OpportunityLineItem.Name}">
            <apex:pageBlockButtons location="bottom">
                <apex:commandButton action="{!gensched}" value="Generate Schedule" rendered="{!OpportunityLineItem.Schedule__c == null}" oncomplete="Return()" />
            </apex:pageBlockButtons>


So I have this but it just returns the original page in my new window, if the user does this a few times they will end up with way too many windows open:

<apex:page standardController="OpportunityLineItem" extensions="ScheduleExtension" docType="html-5.0">
    <apex:form>
    <script> function Return() { 
        window.location.href = 'https://cs63.salesforce.com/'+'{!OpportunityLineItem.ID}' 
    } 
    </script>
        <apex:pageBlock  title="Set Product Schedule for {!OpportunityLineItem.Name}">
            <apex:pageBlockButtons location="bottom">
                <apex:commandButton action="{!gensched}" value="Generate Schedule" rendered="{!OpportunityLineItem.Schedule__c == null}" oncomplete="Return()" />
            </apex:pageBlockButtons>
Best Answer chosen by Jean Grey 10
Andrew EchevarriaAndrew Echevarria
I'd replace "rerender()" in your javascript with alert('test') to see if that is working first. If not, then something else is wrong. If it does work, then you can just refresh the page from javascript by replacing the alert line with window.location.reload();

All Answers

Andrew EchevarriaAndrew Echevarria
I did something similar, this link helped me, let me know if it applies for yours. Essentially it connects the pop up with the parent page and initiates an action upon closing.
https://developer.salesforce.com/forums/?id=906F0000000AUbpIAG
Jean Grey 10Jean Grey 10
Looks cool, but it did not work. I should mention don't have a Save button on the VF page, only a "Generate" button that should create the records, close the window, and refresh the Opportunity Product page all in one click. 
Andrew EchevarriaAndrew Echevarria
I'd replace "rerender()" in your javascript with alert('test') to see if that is working first. If not, then something else is wrong. If it does work, then you can just refresh the page from javascript by replacing the alert line with window.location.reload();
This was selected as the best answer
Jean Grey 10Jean Grey 10
I think I'm getting closer...I was confusing the "Generate Schedule" button on the OLI page (which opens up the VF page) with the "Generate Schedule" button on the actual VF page. How do I add JS to the button on the OLI page so when the VF page is complete it refreshes the original page?