Всем привет.
Такая проблема - пытаюсь создать extentions стандартного контроллера, чтобы прикрутить кнопку к Contacts.
Создал класс апекса
public with sharing class AddCommUserController {
private final Account acct;
private final Contact cont;
private final User usr;
public String ContactOwnerID;
public String ManagerUserID;
public String ManagerEMail;
public String AccName;
public String EmailBody;
public String EmailSubject;
public AddCommUserController(ApexPages.StandardController stdController) {
this.cont = (Contact)stdController.getRecord();
ContactOwnerID = cont.OwnerId;
usr = [SELECT ManagerId FROM User WHERE Id = :ContactOwnerID];
ManagerUserID = usr.ManagerId;
usr = [SELECT Email FROM User WHERE Id = :ManagerUserID];
ManagerEMail = usr.Email;
acct = [SELECT Name FROM Account WHERE Id=:cont.AccountId];
AccName = acct.Name;
EmailSubject = 'Approval request for adding Customer Community User';
EmailBody = 'Please approve new Customer Community User:'+'\n'+
'Account: '+AccName+'\n'+
'Contact: '+cont.FirstName+' '+cont.LastName;
}
public void sendMail(String address, String subject, String body) {
// Create an email message object
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {address};
mail.setToAddresses(toAddresses);
mail.setSubject(subject);
mail.setPlainTextBody(body);
// Pass this email message to the built-in sendEmail method
// of the Messaging class
Messaging.SendEmailResult[] results = Messaging.sendEmail(
new Messaging.SingleEmailMessage[] { mail });
inspectResults(results);
}
// Helper method
private static Boolean inspectResults(Messaging.SendEmailResult[] results) {
Boolean sendResult = true;
// sendEmail returns an array of result objects.
// Iterate through the list to inspect results.
// In this class, the methods send only one email,
// so we should have only one result.
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;
}
}
Страница:
<apex:page standardController="Contact" extensions="AddCommUserController">
<apex:form >
<apex:commandButton value="Add Community User" Action="{!sendMail}">
<apex:param name="address" value="{!ManagerEMail}" />
<apex:param name="subject" value="{!EmailSubject}" />
<apex:param name="body" value="{!EmailBody}" />
</apex:commandButton>
</apex:form>
</apex:page>
В итоге - ругается:
Unknown method 'ContactStandardController.sendMail()
Что я делаю не так?..