function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Shwetal DesaiShwetal Desai 

oncomplete event not working in commandbutton after standard action method

Hello exports, I have a code where i have used "oncomplete" event of apex commandbutton and i have called javascript function on that button's oncomplete event.

Even that command button has standard action mathod "Save" as its action.


Here is my code:


<apex:page StandardController="CertificationList__c" showHeader="false" sideBar="false" id="pgOnlDept"> <style> .labelcol{color:Purple;font-size:9pt;font-weight:Bold;} </style> <apex:form id="frmOnlDept"> <apex:pageBlock id="pbOnlDept"> <apex:pageBlockButtons > <apex:commandButton id="btnSave" action="{!save}" value="Save" oncomplete="back();"/> <apex:commandButton id="btnCancel" action="{!Cancel}" value="Cancel" oncomplete="window.location.reload();"/> </apex:pageBlockButtons> <apex:pageBlockSection title="Information" id="pbsOnlDept"> <apex:inputField value="{!CertificationList__c.CertificationType__c}" id="flg" styleClass="labelcol"/> </apex:pageBlockSection> </apex:pageBlock> </apex:form> <script type="text/javascript"> function back() { window.parent.location.href='{!$Page.CertificateLookup1}?rid={!$CurrentPageReference.parameters.rid}&txt={!$CurrentPageReference.parameters.txt}'; } </script> </apex:page>

this code was working perfectly before few days.


What could be the reason??


Please guide me


Thanks in advance.



Shwetal Desai

Rajesh ShahRajesh Shah

Don't know the exact reason but you can check 2 things:


1. Maybe oncomplete doesn't works with standard actions.


2. Are you sure the function back() is not getting called? Try adding alert in the function and see if it is getting called or not.

David VPDavid VP

It could also be that there's a problem with the Save method (a new validation rule, some field that is now required that wasn't before, user rights or sharing that has been changed etc ...)


Please put an apex:messages tag in your page and monitor the debug logs for the user. That way you'll at least know if something goes wrong.



Shwetal DesaiShwetal Desai

Thanks for replying, here in this page i've used StandardController and standard action mathods "Save" and "Cancel" but after the action done of save i want the user rediercted on another VF page, rather standard View page of the object. that is, why i have used oncomplete event and used javascript function. even i have tried using alert statement there on oncomplete event. but it does not show any message. and when i click on the save button it redirects me on the default view page of the record.


In this object in which i m inserting a record has only one field. and I m providing value to that field, additionally i dont have any validation rules and i have administrator account for this application.



Please guide me to solve it.



David VPDavid VP

I just noticed something else : Since you're not using Ajax (no 'rerender' attribute in the commandbutton), your page just posts to the server. (hence clearing the current page from memory so there's nothing to call there anymore).


 See the docs : oncomplete

The JavaScript invoked when the result of an AJAX update request completes on the client.


Oncomplete only works when the page stays in the browsers memory (which is when you're using Ajax requests).



On a separate note : I would add an extension class to the standardcontroller, override the save() method in there and return the correct PageReference you want to navigate to. That way you at least have control over error handling...





I have a scenario, In a VF page we have check boxes, based on the selection of checkboxes,PDF will be generated on click of a button, currently when we click on the button, balnk page is displayed and after closing and opening again is showing the data.


Basically on click is taking place before action even. please help.


<apex:commandButton value="Generate as PDF"  id="pdfButton" action="{!getselected}" onclick="'/apex/CustomerOverviewPDFPage?id={!Account.Id}');" ></apex:commandButton>


getselected consists of whether check box is selected or not (true or false)



please help , its very urgent