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
sfdclivesfdclive 

email sending error

Hi,

Pls let me know where did i make a mistake. its urgent.

     when i click on send email button it is showing error at multiselect picklist field

Error: j_id0:j_id1:j_id3:Distribution_List: An error occurred when processing your submitted information.

 

 public class sendingemail {
Public String subject{get;set;}
Public String body{get;set;}
Public List<Contact> contactlist;
    public sendingemail(ApexPages.StandardController controller) {
//contact = [select name, lastName, email,Distribution_List__c, Opt_out_Email__c,recordtype.name from Contact where id = :ApexPages.currentPage().getParameters().get('id')];
    }
    public List<Contact> getContact() {
return contactlist;
}
    public PageReference send() {
    contactlist =[select lastName, email,Distribution_List__c, Opt_out_Email__c,recordtype.name from Contact where Opt_out_Email__c = false and Distribution_List__c='DL1;DL2'];
    // Define the email
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
// Sets the paramaters of the email
String addresses;
if (Contactlist[0].Email != null)
{
addresses = Contactlist[0].Email;
// Loop through the whole list of contacts and their emails
for (Integer i = 1; i < Contactlist.size(); i++)
{
if (Contactlist[i].Email != null)
{
addresses += ':' + Contactlist[i].Email;
}
}
}
String[] toAddresses = addresses.split(':', 0);
email.setSubject( subject );
email.setToAddresses(toAddresses);
email.setPlainTextBody( body );
// Sends the email
Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
return null;
    }

}

this is my page.

<apex:page StandardController="Contact" extensions="sendingemail">
<apex:pageBlock title="Send an Email to Your
{!Contact.name}">
<p>Please choose the distribution List</p>
<br />
<apex:form >
<br /><br />
<apex:outputLabel value="Distribution_Lists" for="Distribution_List"/>:<br />
<apex:inputfield value="{!Contact.Distribution_List__c}" />
<br /><br />
<apex:outputLabel value="Subject" for="Subject"/>:<br />
<apex:inputText value="{!subject}" id="Subject" maxlength="80"/>
<br /><br />
<apex:outputLabel value="Body" for="Body"/>:<br />
<apex:inputTextarea value="{!body}" id="Body" rows="10" cols="80"/>
<br /><br />

<br />
<apex:commandButton value="Send Email" action="{!send}" />
</apex:form>

 </apex:pageBlock>
</apex:page>

 

 

Regards

Sri

Vinita_SFDCVinita_SFDC

Hello,

 

Multiselect picklist values can't be parse through command button. Use Java script to parse them.

 

As a wrokaround try to surround the field distribution list under<pageBlockSectionItem>, like:

 

<apex:pageBlockSection title="Test">
<apex:pageBlockSectionItem>
<apex:outputLabel value="Distribution_Lists" for="Distribution_List"/>:<br />
<apex:inputfield value="{!Contact.Distribution_List__c}" />
</apex:pageBlockSectionItem>
</apex:pageBlockSection>