0% found this document useful (0 votes)
6 views

Apex_Program

The document contains a Java class named 'Email' that defines a method for sending emails using specified addresses, subjects, and messages. It includes a test case that initializes email details and calls the sendMail method to send the emails. The code demonstrates the use of arrays to manage multiple email parameters and utilizes Salesforce's Messaging API for sending emails.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Apex_Program

The document contains a Java class named 'Email' that defines a method for sending emails using specified addresses, subjects, and messages. It includes a test case that initializes email details and calls the sendMail method to send the emails. The code demonstrates the use of arrays to manage multiple email parameters and utilizes Salesforce's Messaging API for sending emails.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

##Class

public class Email {


public void sendMail(String [] addresses, String [] subjects, String []
messages) {
Messaging.SingleEmailMessage [] emails = new Messaging.SingleEmailMessage[]
{};
Integer totalMails = addresses.size();
for(Integer i=0; i < totalMails; i++){
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
email.setSubject(subjects[i]);
email.setToAddresses(new List<String> { addresses[i] });
email.setPlainTextBody(messages[i]);
emails.add(email);
}
Messaging.sendEmail(emails);
}
}

## Test Case

String address = '[email protected]';


String subject = 'Hello World';
String body = 'Testing Application written in Apex programming language';
String address1 = '[email protected]';
String subject1 = 'Saleforce Application';
String body1 = 'Test Body....';
String[] addresses = new String[]{},
subjects = new String[]{},
messages = new String[]{}
;addresses.add(address);
subjects.add(subject);
messages.add(body);
addresses.add(address1);
subjects.add(subject1);
messages.add(body1);
Email em = new Email();
em.sendMail(addresses, subjects, messages);

You might also like