Sunday 28 May 2017

Send email to multiple email ids with attachment using apex.

On the visualforce page, create text field and button using standard salesforce visualforce tags and define id and styleClass for the tags  so that tags will be identified when using css and script.

I define page id in <apex:page>  tag and provide id to each and every tag.

Like, I provide id="field"  in <apex:inputText>  but it has id in actual is 'custom:frm:field' with the combination of above defined tags like <apex:form id="frm"> and <apex:page id="custom"> .

In script, Javascript is using to get the value from input field by onclick action on button.




Visualforce Page:

<apex:page sidebar="false" id="custom">

  <!-- This script link will be added when we will use jquery on page-->
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  
  <style>
      .field
      {
            border-color: green;
            border-radius: 1px;
      }
  </style>
  <script>
      
      // Use of javascript
      function showTextValue()
      {
          var val=document.getElementById('custom:frm:field').value;
          if(val!='')
              alert(val); // If alert is block for browser then use console.log(val)
          else
              alert('Please enter name');
              
         return false;
      }
      
      // Use of Jquery
      $(document).ready(function(){
        $(".jbutton").click(function(){
              var val=$(".field").val();
              if(val!='')
                  alert('jquery:='+val); // If alert is block for browser then use console.log(val)
              else
                  alert('jquery:=Please enter name');
              
          });
      });
      
      
  </script>
  <apex:form id="frm">
      Enter Name:<apex:inputText id="field" styleClass="field"/>
      <apex:commandButton id="button" styleClass="button" value="Execute Jscript" style="background: green;color: white;width: 7%;margin: 10px;" onclick="showTextValue()"/>
      <apex:commandButton id="jbutton" styleClass="jbutton" value="Execute Jquery" style="background: green;color: white;width: 7%;margin: 10px;"/>
  </apex:form>
</apex:page>

0 comments:

Post a Comment

If you have any doubts, please let me know.