You need to sign in to do that
Don't have an account?

sending email 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
Hi,
Please change the name of method getContact to anything else because it produces ambiguity with SatndardController name.
Controller:
public List<Contact> getContact() {//change it to getContactsList()....
return contactlist;
}
VF 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>
Now there are two scenarios:-
1. if you want to use Contact standadcontroller variable, then this visualforce is good.
2. if you want to use contactlist then use <apex:pageBlockTable>or <apex:dataTable> or <apex:repeat>.
/** if this post helps you, please throw a kudos by clicking star on left**/
Thanks,
www.grazitti.com
I resolved that one and i edited my code pls check it and tell me where is the mistake