List<Account> myAccounts = [SELECT Id, Name
FROM Account];
String firstAccount = myAccounts[0].Name;
system.debug(firstAccount);
----------------------------------------------------------------------------------------------------------------------------------------------------------------
Map<Id, Account> accountMap = new Map<Id,
Account>([SELECT Id, Name FROM Account]);
Id accId = '0016F00002iaPQ5';
Account account = accountMap.get(accId);
system.debug(account);
Set<ID> accountIds = new
Set<ID>{'001d000000BOaHSAA1','001d000000BOaHTAA1'};
List<Account> accounts =
[SELECT Name FROM Account WHERE Id IN
:accountIds];
public with sharing class EmailManager {
public
static void sendMail(String address, String subject, String body) {
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {address};
mail.setToAddresses(toAddresses);
mail.setSubject(subject);
mail.setPlainTextBody(body);
Messaging.SendEmailResult[] results = Messaging.sendEmail(new
Messaging.SingleEmailMessage[] { mail });
inspectResults(results);
}
private
static Boolean inspectResults(Messaging.SendEmailResult[] results) {
Boolean sendResult = true;
for
(Messaging.SendEmailResult res : results) {
if (res.isSuccess()) {
System.debug('Email sent successfully');
}
else {
sendResult = false;
System.debug('The following errors occurred: ' + res.getErrors());
}
}
return sendResult;
}
}
EmailManager.sendMail('sanjaybaroliya1991@gmail.com',
'Trailhead Tutorial', '123 body');
No comments:
Post a Comment