[SalesForce] page reloads before related record is updated

SEE SOLUTION AT BOTTOM OF QUESTION SINCE I WAS ABLE TO ANSWER IT ON MY OWN

I have a VF page that overrides the Opportunity view page, this is so that I can implement my own product related list. The related list has a Delete link that fires a delete of the opportunity line and also fires a trigger that calls a class method to perform an summary calculation up to the opportunity for some fields.

My problem comes because the Delete link fires this delete action but yet the page reloads BEFORE the opportunity update is completed. This causes the end user to see the "old" opportunity values even though they are being updated. This is true since a second refresh will show the updated opportunity values. What I need is for the Opportunity to be displayed AFTER it is updated and not before. See code below:

Opportunity View Override VF page code:

<apex:column headerValue="Action" style="text-align:center;width:50px;">
            <apex:outputLink target="_blank" title="Click to view record details (new tab/page)" value="/{!oli.id}">
                View  
            </apex:outputLink>
            <apex:commandLink title="Click to delete record" action="{!del}" styleClass="DelBTN" >
                Delete
                 <apex:param name="delname" value="{!oli.id}" assignTo="{!delOLIid}"/> 
            </apex:commandLink>
        </apex:column>

Controller:

 public PageReference Del () {
    if(delOLI!= null) {
    Delete delOLI;
    getOppFieldAndHistory(opp);
    queryOLIs(opp.id);
    }
    return null;
}

Please let me know if you have any input into this issue…

UPDATED SOLUTION:

I found the solution so posting in hope that it may help some other lost soul.
Basically I added a Page reference to the view of the Opportunity (see updated code below), whereas before I was simply letting the page refresh by not providing any rerender attribute.

public PageReference Del () {

    if(delOLI!= null) {
    Delete delOLI;
    getOppFieldAndHistory(opp);
    queryOLIs(opp.id);
    }
    PageReference oppPage = new ApexPages.StandardController(opp).view();
    oppPage.setRedirect(true);
    return oppPage;
}

Best Answer

SOLUTION:

I found the solution so posting in hope that it may help some other lost soul. Basically I added a Page reference to the view of the Opportunity (see updated code below), whereas before I was simply letting the page refresh by not providing any rerender attribute.

public PageReference Del () {

    if(delOLI!= null) {
    Delete delOLI;
    getOppFieldAndHistory(opp);
    queryOLIs(opp.id);
    }
    PageReference oppPage = new ApexPages.StandardController(opp).view();
    oppPage.setRedirect(true);
    return oppPage;
}
Related Topic