0

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.

  • While I did provide a direct answer, it's clear that you don't understand how callbacks work. You might want to do some studying on how JavaScript functions work. – sfdcfox Nov 27 '18 at 5:14
  • You totally right I haven't work with javascript before, definitely will do the study, I started in this thing of salesforce 2 months ago, my prior experience has been with Java, Spring Boot at the back end, not a big fan a frontend... I will follow as you say and let you anything, thanks a lot @sfdcfox – AjFmO Nov 27 '18 at 13:50
1

You're not even using jQuery in your original code. This is one of the complicated setups you could possibly use for this task.

Just use an action function:

<apex:page standardController="myStandarObject" 
           extensions="myExtensionController" showHeader="false"
           applyBodyTag="false" standardStylesheets="false" >
  <apex:form id="form">
    <apex:actionFunction name="sendEmailToDS" action="{!sendEmail}" reRender="form" />
  </apex:form>
  <script>
    if({!object.field == 'value'}) { // make sure it can be called
      window.addEventListener("load", sendEmailToDS, false);
    }
  </script>
</apex:page>
| improve this answer | |
  • Wow, just wow, I had to adjust some minimal things, but, worked like a charm. Now will study javascript and continue learning about this... The place where I'm working just gave me the trailhead beginner developer training and jump to the work, God I feel frustrated. – AjFmO Nov 27 '18 at 14:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.