You need to sign in to do that
Don't have an account?
![Abhishek Kumar 407 Abhishek Kumar 407](https://dfc-org-production.my.site.com/img/userprofile/default_profile_45_v2.png)
Can someone help here as I've a requirement: How to count no. of words in a given email body? I am unable to achieve it!
Here is the apex and VF code:
//Apex Code public class sendEmailbuttonApex { public Account accounts {set;get;} public String subject { get; set; } public String body { get; set; } public sendEmailbuttonApex(Apexpages.StandardController controller) { accounts=(Account)controller.getRecord(); } public PageReference sendEmail() { List<Contact> conList=[Select Id, Email from contact where Email='abhishekk.twopirconsulting@gmail.com']; system.debug(conList); List<String> mail=new List<String>(); for(Contact c:conList) { mail.add(c.Email); } Messaging.SingleEmailMessage msg1=new Messaging.SingleEmailMessage(); msg1.setToAddresses(mail); msg1.setSubject(subject); msg1.setPlainTextBody(body); Messaging.Email[] emails=new Messaging.Email[]{msg1}; Messaging.sendEmail(emails); PageReference p=new PageReference('/'+accounts.id); p.setRedirect(true); return p; } }
//VF code <apex:page docType="HTML-5.0" standardController="Account" extensions="sendEmailbuttonApex"> <apex:form> <script src="http://code.jquery.com/jquery-1.8.3.min.js"></script> <script> $(document).ready(function() { $("#word_count").on('keydown', function(e) { //j$('[id$=word_count]').on('keydown', function(e) { var words = $.trim(this.value).length ? this.value.match(/\S+/g).length : 0; if (words <= 200) { $('#display_count').text(words); $('#word_left').text(200-words) }else{ if (e.which !== 8) e.preventDefault(); } }); }); </script> <br /><br /> <apex:outputLabel value="Subject" for="Subject"/>:<br /> <apex:inputText value="{!subject}" id="Subject" maxlength="80"/> <br /><br /> <apex:outputLabel value="Body" for="word_count"/>:<br /> <apex:inputTextarea id="word_count" cols="30" rows="10" value="{!body}"/> <br /> Total word Count : <span id="display_count">0</span> words. Words left : <span id="word_left">200</span> <br /><br /><br /> <apex:commandButton value="Send Email" action="{!sendEmail}" /> </apex:form> </apex:page>
All Answers