-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEinsteinChatbotsPostWorkOrderMessage.cls
43 lines (39 loc) · 2.04 KB
/
EinsteinChatbotsPostWorkOrderMessage.cls
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
global class EinsteinChatbotsPostWorkOrderMessage
{
@InvocableMethod(label='Einstein Chatbots - Post Message to WorkOrder' description='Posts a message to the Work Order Chatter Feed')
global static void Post2WO(List<Post2WORequest> requests)
{
System.debug('Entering Posting method...');
List<ServiceAppointment> results = new List<ServiceAppointment>();
For (Post2WORequest objPost2WORequest : requests)
{
//Post simple message to the Work Order
//FeedItem post = new FeedITem();
//post.body = objPost2WORequest.message;
//post.ParentID = objPost2WORequest.objSA.ParentRecordId;
//insert post;
String salesforceHost = System.Url.getSalesforceBaseURL().toExternalForm();
String url = salesforceHost + '/services/data/v23.0/chatter/feeds/record/' + objPost2WORequest.objSA.ParentRecordId + '/feed-items';
HttpRequest req = new HttpRequest();
req.setMethod('POST');
req.setEndpoint(url);
req.setHeader('Content-type', 'application/json');
req.setHeader('Authorization', 'OAuth ' + UserInfo.getSessionId());
req.setBody('{ "body" : { "messageSegments" : [ { "type": "text", "text" : "' + 'Message from ' + objPost2WORequest.objContact.FirstName + ' ' + objPost2WORequest.objContact.LastName + ':' + '" }, { "type": "text", "text" : "' + '\\n\'' + objPost2WORequest.message + '\'\\n\\n' + '" }, { "type": "mention", "id" : "' + objPost2WORequest.objServiceResource.RelatedRecordId + '" }] } }');
Http http = new Http();
HTTPResponse res = http.send(req);
return;
}
}
global class Post2WORequest
{
@InvocableVariable(required=true)
global string message;
@InvocableVariable
global ServiceAppointment objSA;
@InvocableVariable
global Contact objContact;
@InvocableVariable
global ServiceResource objServiceResource;
}
}