Created
May 28, 2016 03:26
-
-
Save cdcarter/5a8fcf72e9d0be7c88942a365f5f6936 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
global class Summer16EmailAction { | |
@invocableMethod | |
global static void renderEmailToChatter(List<EmailRequest> emails) { | |
List<ConnectApi.BatchInput> batchInputs = new List<ConnectApi.BatchInput>(); | |
for(EmailRequest email : emails) { | |
ConnectApi.FeedItemInput input = new ConnectApi.FeedItemInput(); | |
input.subjectId = email.getFeedId(); | |
ConnectApi.MessageBodyInput body = new ConnectApi.MessageBodyInput(); | |
body.messageSegments = new List<ConnectApi.MessageSegmentInput>(); | |
ConnectApi.TextSegmentInput textSegment = new ConnectApi.TextSegmentInput(); | |
textSegment.text = email.getPlainTextBody(); | |
body.messageSegments.add(textSegment); | |
input.body = body; | |
ConnectApi.BatchInput batchInput = new ConnectApi.BatchInput(input); | |
batchInputs.add(batchInput); | |
} | |
ConnectApi.ChatterFeeds.postFeedElementBatch(Network.getNetworkId(), batchInputs); | |
} | |
global class EmailRequest { | |
@invocableVariable(required=true) global Id whoId; | |
@invocableVariable(required=true) global Id whatId; | |
@invocableVariable(required=true) global Id templateId; | |
@invocableVariable(required=true) global Id feedId; | |
private Messaging.SingleEmailMessage msg; | |
global Id getFeedId() {return this.feedId;} | |
global String getPlainTextBody() { return this.render().getPlainTextBody();} | |
private Messaging.SingleEmailMessage render() { return this.msg = Messaging.renderStoredEmailTemplate(templateId, whoId, whatId);} | |
} | |
} |
@jodim -
Id contactId = '0033600000J3DZ7';
Id accountId = '0013600000QG6qS';
Id templateId = '00X36000001996H'
Messaging.SingleEmailMessage msg = Messaging.renderStoredEmailTemplate(templateId, contactId, accountId);
system.debug(msg.getPlainTextBody());
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
OK, I put some debug statements in there, and this is all it's showing
[26]|DEBUG|ConnectApi.MessageBodyInput[messageSegments=(ConnectApi.TextSegmentInput[text=])]
I added a debug of
System.debug(email.getPlainTextBody());
and it just returned nothing.
The email is actually sending, and the rest of the process is working.
So I'm not sure where to turn next with it. I may have to just give up on this idea for now. So close, yet so far, because it works perfectly well for HTML emails.