function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Developer.mikie.Apex.StudentDeveloper.mikie.Apex.Student 

Please Help - Value is not valid, Cause = \n + selectList, Solution = ??

Hi There,

I am attempting to create an email app. I works pretty well, however I have continuously come into an error:

Error:j_id0:j_id79:j_id80:ComponentForm:j_id90:j_id91:myEmailModal:j_id97:myPanel1:j_id100:Templates: Validation Error: Value is not valid

The only thing i can work out is the i thinka  combination of using \n and selectlist is causing the problems. I have a selectlist which is designed to paste a string into an inputtext area depending on your selectlist pick. This works fine, but when I select a tempalte that includes \n it errors with the above message after I try and encode() it. I click the encode button once and it errors, i click a second time and it randomly works. But the selectlist is no longer on that particular tempalt echoice. However, when i use a more simple string - E.G. 'Test', it works without issues and encodes the email fine.

Please help

Component
<apex:component controller="DestinyEmailComponent"> <apex:attribute type="boolean" name="ImportVisualStrap" description="Set this value to true if visualstrap has not already been imported on your page" default="true"/> <apex:attribute name="AssociatedAccount" required="true" type="Id" description="id of Associated Account" assignTo="{!AccountId}"/> <!-- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <script src="{!URLFOR($Resource.charCounter)}" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function(){ $('.countable').jqEasyCounter({ 'maxChars': 300000, 'maxCharsWarning': 20000, 'msgFontSize': '12px', 'msgFontColor': '#000', 'msgFontFamily': 'Verdana', 'msgTextAlign': 'left', 'msgWarningColor': '#F00', 'msgAppendMethod': 'insertAfter' }); }); </script> --> <script> function MessageRender(Body) { var MessageBodyHidden2 = Body.options[Body.selectedIndex].value; var MessageBody = document.getElementById('j_id0:j_id79:j_id80:ComponentForm:j_id90:j_id91:myEmailModal:j_id97:myPanel1:j_id100:MessageBody'); MessageBody.value = MessageBodyHidden2; MessageBodyHidden2.value = ''; //updateState(); } function EncodeEmail() { //var MessageBody = document.getElementById('j_id0:j_id79:j_id80:ComponentForm:j_id90:j_id91:myEmailModal:j_id97:myPanel1:j_id100:MessageBody'); //debugger; //var EncodeString = MessageBody.value; //debugger; //EncodeString = EncodeString.trim(); //debugger; //var MessageBodyT = document.getElementById('j_id0:j_id79:j_id80:ComponentForm:j_id90:j_id91:myEmailModal:j_id97:myPanel1:j_id100:MessageBodyT'); //debugger; //MessageBodyT.value = MessageBodyT; //MessageBodyT.value = "hello"; } </script> <apex:outputPanel rendered="{!ImportVisualStrap}" layout="none"> <c:importvisualstrap theme="cosmos"/> </apex:outputPanel> <apex:componentBody > <apex:form id="ComponentForm" > <c:visualstrapblock > <div align="center"> <apex:commandButton value="Open Email App" onclick="return false;" html-data-toggle="modal" html-data-target="#myEmailModal" styleClass="btn-success btn-sm"/> </div> <br/> <!--modal that will be displayed to the user--> <c:modal id="myEmailModal"> <c:panel id="myPanel1" title="Destiny Email App" type="primary" > <apex:outputPanel layout="block" id="MyModalPanel"> <div align="left"> <apex:outputLabel value="Select Contact" for="Contacts"/> <apex:outputPanel layout="block"> <apex:actionRegion > <apex:selectList id="Contacts" size="1" value="{!EmailContact}" title="Type" styleClass="form-control"> <!-- <apex:actionSupport event="onchange" action="{!ProcessData}"/> --> <apex:selectOptions value="{!Contacts}"></apex:selectOptions> </apex:selectList> </apex:actionRegion> <br/> <br/> </apex:outputPanel> <apex:outputLabel value="Select Contact" for="Templates"/> <apex:outputPanel layout="block"> <apex:actionRegion > <apex:selectList id="Templates" size="1" value="{!Template2}" onchange="javascript:MessageRender(this)" title="Type" styleClass="form-control"> <!-- <apex:actionSupport event="onchange" action="{!EncodeEmail}" /> rerender="MyModalPanel,ScriptPanel"--> <apex:selectOptions id="TemplateOptions" value="{!Templates2}"></apex:selectOptions> </apex:selectList> </apex:actionRegion> <br/> <br/> </apex:outputPanel> </div> <br/> <div align="left"> <apex:outputLabel value="Text Message:" for="MessageBody"/> <br/> <apex:inputTextarea rows="4" cols="70" label="Text Message Body: " value="{!MessageBody}" id="MessageBody"/> <br/><!-- styleClass="countable" <apex:actionFunction name="updateState" rerender="ScriptPanel" action="{!EncodeEmail}" /> --> <br/> <apex:outputText value="{!MessageBodyT}" escape="false" id="MessageBodyT"/> </div> <apex:pagemessages /> <apex:outputPanel layout="block" id="Footer" styleClass="modal-footer"> <div align="center"> <!-- rendered="{!NOT(isComplete)}" --> <apex:commandButton value="Send Email" styleClass="btn-success" onclick="$(this).button('loading')" html-data-loading-text="Sending..." action="{!SendEmail}" /> <apex:commandButton value="Close SMS App" styleClass="btn-danger" action="{!CloseApp}" /> <apex:commandButton value="Encode" styleClass="btn-danger" onclick="$(this).button('loading')" html-data-loading-text="Encoding..." action="{!EncodeEmail}" /> <apex:commandButton value="Encode2" styleClass="btn-danger" html-data-loading-text="Encoding..." onclick="EncodeEmail(); $(this).button('loading'); " /> <apex:commandButton value="Encode3" styleClass="btn-warning" action="{!EncodeEmail}" /> <!--<apex:commandButton value="Close SMS App" styleClass="btn-warning" "action="{!CloseApp}" html-data-dismiss="modal"/> --> </div> </apex:outputPanel> <apex:outputPanel rendered="{!isComplete}" id="ScriptPanel" > <script> $('#myEmailModal').modal('hide'); $('#myEmailModal').modal('show'); </script> </apex:outputPanel> </apex:outputPanel> </c:panel> </c:modal> </c:visualstrapblock> </apex:form> </apex:componentBody> </apex:component>



class
public with sharing class DestinyEmailComponent {
    
  public Id AccountId;//Associated Account
  String EmailContact;//String Received from Contact List
  public String Template2 {get;set;}//Template string
  
  String ToEmail {get;set;}//Contact Mobile Number
  public String MessageBody {get;set;}//Text Message Body
  
  String userName = UserInfo.getUserName(); //Query UserName
  User activeUser = [Select Username,Destiny_Office__c, Name, Title, Email_Signature__c From User where Username = : userName]; //Query User Record
  
  String EmailFooterHTML  {get;set;}
  String EmailHeaderHTML  {get;set;}
String EmailParagraphStart  {get;set;}
String EmailParagraphEnd  {get;set;}
  
   public String MessageBodyT {get;set;}//Text Message Body
  
  public Boolean isComplete{get;set;}
  map<id, Contact> ConDataMap = new Map<id, Contact>();
  
  
  public DestinyEmailComponent (){ 
  }
    
  public void setAccountId (Id s) {
    AccountId = s;
  }
    
  public String getAccountId() {
    return AccountId;
  } 
  
  public string getMessageBody (){
    return MessageBody;
    }
    
    public string getMessageBodyT (){  
    return MessageBodyT;
    }
    
        public void setMessageBodyT (string s){
    MessageBodyT=s;            
    }
  public void setMessageBody (string s){
    MessageBody=s;            
    }
       
    
    public List<SelectOption> getContacts() 
       {
       
 List<Contact> Contact=[select id, FirstName, LastName, Name, MobilePhone, Email From Contact where AccountId =: AccountId order by createddate]; //Query Associated Contacts
        
 if(Contact != null && Contact.size() > 0){
for(Contact C:Contact  ){ 
 ConDataMap.put(C.Id, C);
                         }
                                             }
       List<SelectOption> options = new List<SelectOption>();
       options.add(new SelectOption('','Select Contact'));
       for(integer i=0;i< Contact.size();
       i++)
        {
        options.add(new SelectOption(Contact[i].Id,Contact[i].Name+' -('+Contact[i].Email+')'));       
        }
        return options;
        }
               
        
        public List<SelectOption> getTemplates2() 
       {
       
       
       List<SelectOption> options2 = new List<SelectOption>();
       options2.add(new SelectOption('','Select Template'));
              
       String HTMLTest2 = 'Test';
       options2.add(new SelectOption(HTMLTest2,'HTMLTest2'));
       
       String ApplicationSubmitted = EmailHandler.Fin_ApplicationSubmitted;
       options2.add(new SelectOption(ApplicationSubmitted,'Application Submitted'));
       
        String Test  = EmailHandler.Fin_Test;
       options2.add(new SelectOption(Test,'Test'));
       
        return options2;
       
       
       }
        
        
        
 public String getEmailContact() {
            return EmailContact;
        }
        
public void setEmailContact(String EmailContact) {this.EmailContact= EmailContact;}

 public String getTemplate2() {
            return Template2;
        }
        
public void setTemplate2(String Template2) {this.Template2= Template2;}
        
        
        Public void ProcessData(){
        
If(EmailContact != null && ConDataMap.get(EmailContact).Email != null){
ToEmail = ConDataMap.get(EmailContact).Email;
} 
}

Public void EncodeEmail(){
Template2 = null;

  String MessageBodySend = EmailHandler.EmailHeaderHTML+EmailHandler.EmailParagraphStart+MessageBody+EmailHandler.EmailParagraphEnd+EmailHandler.EmailFooterHTML;

  MessageBodySend = MessageBodySend.trim();   
  MessageBodySend   = MessageBodySend.replace('\n','</p><p style="color: #00204e; font-family: Arial, Helvetica, sans-serif; font-size: 12px;">');
   MessageBodySend  = MessageBodySend.replace('  ','&nbsp');
    MessageBodyT = MessageBodySend;
    
    isComplete = true;

}




    //Message Function (Via Email to @sms.exemail.com.au)
  public void SendEmail() {
EncodeEmail();
ProcessData();
  
  try{
   
        EmailHandler.sendDestinyEmail(ToEmail,MessageBodyT);
        ApexPages.Message Successmsg = new ApexPages.Message(ApexPages.severity.confirm,'Your Email is being processed!');
        ApexPages.addMessage(Successmsg);
        
      }
catch(Exception ex){
                    Apexpages.addMessages(ex);

                    }
                   
     isComplete = true;
                                }
                                
                                
                                
 public void CloseApp() {
 
 ToEmail = null;
 MessageBody = null;
 EmailContact = null;
 Template2 = null;
 isComplete = False;
 
 }

    
    
    
    
  
}