I am trying to call an apex method from my visualforce page using javascript method.
<apex:page docType="html-5.0" showHeader="false" expires="" sidebar="false" title="Connection" controller="ConnectionController">
<apex:includeScript value="/soap/ajax/21.0/connection.js"/>
<apex:includeScript value="/soap/ajax/21.0/apex.js"/>
<script type="text/javascript">
function closeWindow() {
setTimeout(function() {
window.close();
CallApexMethod();
}, 10000);
}
window.onload = closeWindow();
</script>
<apex:form id="callApexMethod">
<apex:actionFunction name="CallApexMethod" action="{!retrieveMethod}" />
</apex:form>
</apex:page>
And my controller is:
public class ConnectionController {
public PageReference retrieveMethod() {
System.debug('Inside Method');
// some logic
return null;
}
}
It is not even printing System.debug in my logs.
Not sure If I am missing something.
I know there is a way to do it with javascript remoting as well but its a very small part and can be done by
So I was trying to do that.
Best Answer
This is because you first close the window and then call the methods. Try to change there order
or it will be better if you call
window.close();
fromoncomplete
of your action function.