You need to sign in to do that
Don't have an account?
Deepika Rahangdale
I want a test class of
public class ContactRelatedController {
public string accid ;
public ContactRelatedController (){
accid = apexpages.currentpage().getparameters().get('id');
system.debug('Accid'+accid);
}
//Our collection of the class/wrapper objects cContact
public List<cContact> contactList {get; set;}
//This method uses a simple SOQL query to return a List of Contacts
public List<cContact> getContacts() {
if(contactList == null) {
contactList = new List<cContact>();
for(Contact c : [select Id, Name, Email, Phone from Contact where AccountId=:accid]) {
// As each contact is processed we create a new cContact object and add it to the contactList
contactList.add(new cContact(c));
}
}
return contactList;
}
public PageReference processSelected() {
//We create a new list of Contacts that we be populated only with Contacts if they are selected
List<Contact> selectedContacts = new List<Contact>();
//We will cycle through our list of cContacts and will check to see if the selected property is set to true, if it is we add the Contact to the selectedContacts list
for(cContact cCon : getContacts()) {
if(cCon.selected == true) {
selectedContacts.add(cCon.con);
}
}
// Now we have our list of selected contacts and can perform any type of logic we want, sending emails, updating a field on the Contact, etc
for(Contact con : selectedContacts) {
string conEmail = con.Email;
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
// Strings to hold the email addresses to which you are sending the email.
String[] toAddresses = new String[] {conEmail};
//String[] ccAddresses = new String[] {‘smith@gmail.com’};
// Assign the addresses for the To and CC lists to the mail object.
mail.setToAddresses(toAddresses);
// mail.setCcAddresses(ccAddresses);
mail.setSubject('New Mail Created using VF' );
// mail.setPlainTextBody('Thank for U are created mail sussessful');
mail.setHtmlBody('Thank for U are created mail sussessful Thank for Contacting');
// Send the email you have created.
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
// system.debug(con);
}
return null;
}
// This is our wrapper/container class. A container class is a class, a data structure, or an abstract data type whose instances are collections of other objects. In this example a wrapper class contains both the standard salesforce object Contact and a Boolean value
public class cContact {
public Contact con {get; set;}
public Boolean selected {get; set;}
//This is the contructor method. When we create a new cContact object we pass a Contact that is set to the con property. We also set the selected value to false
public cContact(Contact c) {
con = c;
selected = false;
}
}
}
public string accid ;
public ContactRelatedController (){
accid = apexpages.currentpage().getparameters().get('id');
system.debug('Accid'+accid);
}
//Our collection of the class/wrapper objects cContact
public List<cContact> contactList {get; set;}
//This method uses a simple SOQL query to return a List of Contacts
public List<cContact> getContacts() {
if(contactList == null) {
contactList = new List<cContact>();
for(Contact c : [select Id, Name, Email, Phone from Contact where AccountId=:accid]) {
// As each contact is processed we create a new cContact object and add it to the contactList
contactList.add(new cContact(c));
}
}
return contactList;
}
public PageReference processSelected() {
//We create a new list of Contacts that we be populated only with Contacts if they are selected
List<Contact> selectedContacts = new List<Contact>();
//We will cycle through our list of cContacts and will check to see if the selected property is set to true, if it is we add the Contact to the selectedContacts list
for(cContact cCon : getContacts()) {
if(cCon.selected == true) {
selectedContacts.add(cCon.con);
}
}
// Now we have our list of selected contacts and can perform any type of logic we want, sending emails, updating a field on the Contact, etc
for(Contact con : selectedContacts) {
string conEmail = con.Email;
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
// Strings to hold the email addresses to which you are sending the email.
String[] toAddresses = new String[] {conEmail};
//String[] ccAddresses = new String[] {‘smith@gmail.com’};
// Assign the addresses for the To and CC lists to the mail object.
mail.setToAddresses(toAddresses);
// mail.setCcAddresses(ccAddresses);
mail.setSubject('New Mail Created using VF' );
// mail.setPlainTextBody('Thank for U are created mail sussessful');
mail.setHtmlBody('Thank for U are created mail sussessful Thank for Contacting');
// Send the email you have created.
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
// system.debug(con);
}
return null;
}
// This is our wrapper/container class. A container class is a class, a data structure, or an abstract data type whose instances are collections of other objects. In this example a wrapper class contains both the standard salesforce object Contact and a Boolean value
public class cContact {
public Contact con {get; set;}
public Boolean selected {get; set;}
//This is the contructor method. When we create a new cContact object we pass a Contact that is set to the con property. We also set the selected value to false
public cContact(Contact c) {
con = c;
selected = false;
}
}
}
Try Below Code
Important Didn't Know cCon.selected == true Field Or CheckBox On Page Please Mark It As Best Answer If It Helps
Thank You!