For the complete documentation index, see llms.txt. This page is also available as Markdown.

Method: generateEmail

Why?

Use generateEmail when you need to leverage the advanced styling, conditional logic, and related-list capabilities of S-Docs within an automated email workflow. This method allows you to bypass the limitations of standard Salesforce Email Templates while maintaining full control over the distribution via Apex.

What: Technical Signatures

The SDK provides three overloaded versions of this method depending on your required output.

1. Generate HTML Body Only

Best for when you only need the compiled content to pop into a custom UI or a standard Apex mailer.

Java

public static String generateEmail(Id templateId, Id recordId)
  • Returns: String (The compiled HTML body).

2. Generate Serialized Email Object (with Routing)

Best for when you want S-Docs to handle the "To," "CC," and "Subject" logic defined in the template.

Java

public static String generateEmail(Id templateId, Id recordId, SDOC.EmailOptions options)
  • Returns: String (A JSON-serialized Messaging.SingleEmailMessage object).

3. Generate with Existing Attachments

Best for sending an email that includes previously generated S-Doc files as attachments.

Java

  • Returns: String (A JSON-serialized Messaging.SingleEmailMessage object).


Solve: Implementation Patterns

Scenario A: Simple HTML Injection

Use this to grab the S-Docs content and send it using standard Salesforce Apex.

Java

Scenario B: Advanced Routing with EmailOptions

Use this to define CC addresses and specific S-Doc attachments programmatically.

Java


Supporting Class: SDOC.EmailOptions

Property

Type

Description

toAddresses

List<String>

List of primary recipients.

ccAddresses

List<String>

List of CC recipients.

emailSubject

String

Overrides the subject line defined in the template.

sdocIdsToAttach

List<Id>

IDs of SDOC__SDoc__c records to include as attachments.

replyToEmail

String

Sets the "Reply-To" header.


⚠️ Constraints & Limitations

  • Trigger Context: Direct invocation within a Trigger is prohibited. Use a Queueable or @future method.

  • Email Limits: Sending emails via the SDK counts toward your daily Salesforce Org email limits.

  • Attachment Logic: When attaching S-Docs, ensure the running user has "Read" access to the SDOC__SDoc__c records and their related ContentVersion files.

  • Sharing Rules: If enforceSharingRules is set to true, the SDK will respect Salesforce private sharing models; if the user cannot see the record, the email generation will fail.

Last updated

Was this helpful?