On click of a Save Button, I am saving a record in Controller and in VF Page I have added oncomplete attribute to that Button to redirect to another page. There are some criteria to save a record, If not fulfilled an error msg is thrown else will save and should be redirected to another page.
Visualforce page:
<apex:commandButton status="sts" value="SavenContinue" title="SavenContinue" styleClass="btn btn-info" rerender="err" oncomplete="highlightactive('Tab2','Second Tab','First Tab');" action="{!SaveMethod}" />
Controlelr:
Public pagereference Save(){
try{
IF(Obj.LName != '' && Obj.LName != NULL){
insert Obj;
}
else{
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'Please fill the LastName*'));
}
}
catch(Exception e){
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,e.getMessage()));
}
}
The issue I am facing is, whether there is an error or not tab1 is being redirected to tab2. But I need to throw an error instead of redirecting to tab2. Only on successful save tab2 should be displayed.
Please let me know what I am missing in this code.