Sample Custom Apex Class to Send Email
You can define your own custom Apex class and method and use it when configuring the custom action of type EmailThis section provides the format for the request and response JSON to send an email.
The data dictionary for the send email feature is described in the following table.
Name
Data Type
recordId
string
from
string
to
string array
cc
string array
bcc
string array
attachmentId
string array
templatedId
string
recipientId
string
status
boolean
message
string
The Request JSON format is as follows:
{
"recordId" : "",
"from" : "",
"to" : [ "", "" ],
"cc" : [ "", "" ],
"bcc" : [ "", "" ],
"attachmentId" : [ "", "" ],
"templatedId" : "",
"recipientId" : ""
}
The attributes defined in the Request JSON are described in the following table.
Attributes
Description
recordId
Email id to which the email needs to be sent.
from
Email id from which the email needs to be sent.
to
Email id to which the email needs to be sent.
cc
Email id to which the email needs to be Cc’d
bcc
Email id to which the email needs to be Bcc'd.
attachmentId
A list containing the file names of the binary and text files to be attached to the email.
templatedId
Template Id of the selected email Id.
recipientId*
Contact Reference Id which needs to be passed for the email to be sent.
The Response JSON format is as follows:
{
"success" : true or false,
"message" : ""
}
The attributes defined in the Response JSON are described in the following table.
Attributes
Description
success
If the custom function sent the email successfully, then set it to true, else false.
message
If the success attribute in the response is false, then this message is sent to the user.
The sample Apex class structure is as follows:
Global class ClassName implements callable {
public Object call(String action, Map < String, Object > argsMap) {
switch on action {
// Assume 'sendCustomEmail' is a method name that the user has configured.
when 'sendCustomEmail' {
return sendCustomEmail(argsMap);
}
when
else {
throw new SVMXException('Method not implemented');
}
}
}

/**
* Actual implementation for sending an email.
*
* @param argMap - input data map
* {
"recordId" : "",
"from" : "",
"to" : [ "", "" ],
"cc" : [ "", "" ],
"bcc" : [ "", "" ],
"attachmentId" : [ "", "" ],
"templatedId" : "",
"recipientId" : ""
}
*
* @return Map<String, Object> - { 'success' : true/false, 'message' : 'Return message in case of error'}
*/
public Map < String, Object > sendCustomEmail(Map < String, Object > argMap) {

}

}
* 
The Class Name and Method Name must be set to the exact name defined in the custom Apex class and method when configuring the Custom Action of type Email. For example, "Classname" and "sendCustomEmail".
Was this helpful?