Well, I've been struggling the whole day to make this happen.
I have a custom button, that calls a custom VFP, this VFP has an apex:commandbutton, that sents an email (method from the controller) and redirect you to DocuSign() via onClick attribute, now the requirement is, that the custom button from page record just sents the email and redirect to DocuSign.
What I had in mind was just to make the and via javascript make something like on page load setTimeOut(internal click to my apex button, 8000).
I have tried everything and still can make it happen, added JQuery but whenever I try I got errors.
This is my VFP.
<page standardController="myStandarObject" extensions="myExtensionController" showHeader="false"
applyBodyTag="false" standardStylesheets="false" >
<apex:includeScript value="{!URLFOR($Resource.jQuery, '/jquery-3.3.1.min.js')}"/>
<apex:includeScript value="{!URLFOR($Resource.jQuery, '/jquery-ui.min.js')}"/>
<!--<body onload="$('{!$Component.sendWithDS}').click()" style="display:none;">-->
<body style="display:none;">
<apex:outputPanel layout="block">
<apex:form>
<apex:commandButton id="sendWithDS" value="Send" action="{!sendEmail}" Onclick="SendDocuSign()" rendered="{!object.Field == 'Value'}"/>
</apex:form>
</apex:outputPanel>
</body>
<script type="text/javascript">
function redirect(){
document.getElementById('{!$Component.sendWithDS}').click();
}
window.onload = window.setTimeout(redirect(),10000);
</script>
</apex:page>
I don't know what else to do, I've tried a lot of things, tried to make in onLoad attribute at body tag.
This is the error I'm currently getting.
Uncaught TypeError: Cannot read property 'click' of null at redirect.
Thanks in advance.