i am currently using a inline VF page to perform an update on an Sobject. The inline Vf page a picklist field and a button which will update the sobject with the values entered in the picklist. Now, we all know there are lotzzz of examples on how to refresh the main browser window through a inline VF page.
But i need to refresh the main window only if there was no error during the update of the sobject which happens on the click of the button. If there is any validation rule or any other exceptions which prevents the update i am showing the pagemessage on screen.
Now how can i conditionally refresh the main browser based on the success of the sobject record.
Current Apex method that is written for the button(notice i am setting the boolean as true if there is any exception)
public pagereference updateDelegatedUser(){
try{
update caserec;
}catch (exception e)
{
haserror = true;
ApexPages.addmessages(e);
}
return null;
}
VF button
<apex:commandButton oncomplete="refresh();" value="Update" rerender="myform" status="waitingStatusLoad" action="{!updateDelegatedUser}"/>
<script>
function refresh()
{
document.getElementById('{!$Component.myform.btn}').style.visibility="hidden";
//need a condition check here for the below refresh
window.parent.location.replace('/{!$CurrentPage.parameters.id}');
}
</script>