Last active
January 25, 2018 19:36
-
-
Save winniecluk/52347423a9f7163466c7732b9c713f82 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
public static void createNotification(Opportunity o, Id submitterId, String distOptions, String text, List<Id> workItemIds){ | |
List<CollaborationGroup> uList = [ | |
SELECT Id,Name | |
FROM CollaborationGroup | |
WHERE Name = 'Bridge Underwriters' | |
OR Name = 'Term Underwriters' | |
OR Name = 'Capital Markets' | |
]; | |
Map<String,Id> um = new Map<String,Id>(); | |
for (CollaborationGroup u : uList){ | |
um.put(u.Name, u.Id); | |
} | |
Id distId; | |
if (o.RecordType.Name == 'LOC Loan' || o.RecordType.Name == 'Single Asset Loan'){ | |
distId = um.get('Bridge Underwriters'); | |
} else if (o.RecordType.Name == 'Term Loan'){ | |
distId = um.get('Term Underwriters'); | |
} | |
Id capMarketsId = um.get('Capital Markets'); | |
Id analystId; | |
if (null != o.CAF_Analyst__c){ | |
analystId = o.CAF_Analyst__c; | |
} | |
ConnectApi.MessageBodyInput messageInput = new ConnectApi.MessageBodyInput(); | |
messageInput.messageSegments = new List<ConnectApi.MessageSegmentInput>(); | |
// distOptions: bridgeOnly, termOnly, capitalMarketsOnly, all | |
if ( distOptions == 'loanOnly' ){ | |
System.debug('inside distOption loadOnly'); | |
ConnectApi.MentionSegmentInput mentionSegment = new ConnectApi.MentionSegmentInput(); | |
mentionSegment.id = distId; | |
messageInput.messageSegments.add(mentionSegment); | |
} | |
else if ( distOptions == 'capitalMarketsOnly') { | |
System.debug('inside distOption capMarketsOnly'); | |
ConnectApi.MentionSegmentInput mentionSegment = new ConnectApi.MentionSegmentInput(); | |
mentionSegment.id = capMarketsId; | |
messageInput.messageSegments.add(mentionSegment); | |
} | |
else if ( distOptions == 'all') { | |
System.debug('inside distOption all'); | |
ConnectApi.MentionSegmentInput mentionSegment = new ConnectApi.MentionSegmentInput(); | |
mentionSegment.id = o.OwnerId; // The ID of the user to mention. | |
messageInput.messageSegments.add(mentionSegment); | |
ConnectApi.MentionSegmentInput mentionSegment2 = new ConnectApi.MentionSegmentInput(); | |
mentionSegment2.id = distId; | |
messageInput.messageSegments.add(mentionSegment2); | |
ConnectApi.MentionSegmentInput mentionSegment3 = new ConnectApi.MentionSegmentInput(); | |
mentionSegment3.id = submitterId; | |
messageInput.messageSegments.add(mentionSegment3); | |
ConnectApi.MentionSegmentInput mentionSegment4 = new ConnectApi.MentionSegmentInput(); | |
mentionSegment4.id = capMarketsId; | |
messageInput.messageSegments.add(mentionSegment4); | |
} | |
if (null != analystId){ | |
ConnectApi.MentionSegmentInput mentionSegment5 = new ConnectApi.MentionSegmentInput(); | |
mentionSegment5.id = analystId; // The ID of the user to mention. | |
messageInput.messageSegments.add(mentionSegment5); | |
} | |
ConnectApi.TextSegmentInput textSegment = new ConnectApi.TextSegmentInput(); | |
textSegment.text = text; | |
messageInput.messageSegments.add(textSegment); | |
ConnectApi.FeedItemInput input = new ConnectApi.FeedItemInput(); | |
input.body = messageInput; | |
input.subjectId = o.Id; | |
if (null != workItemIds){ | |
ConnectApi.LinkCapabilityInput lci = new ConnectApi.LinkCapabilityInput(); | |
lci.url = 'https://cvest--full.lightning.force.com/one/one.app#/sObject/' + workItemIds[0] + '/view'; | |
lci.urlName = 'Test Link'; | |
ConnectApi.FeedElementCapabilitiesInput feci = new ConnectApi.FeedElementCapabilitiesInput(); | |
feci.link = lci; | |
input.capabilities = feci; | |
} | |
ConnectApi.FeedElement fi = ConnectApi.ChatterFeeds.postFeedElement(Network.getNetworkId(), input); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment