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);} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@jodim -