You need to sign in to do that
Don't have an account?
Jean-Sebastien Dorais
Apex: Task link to opportunity and user
I've got the following Apex class that successfully pulls data from the 'Task' object. I need to lookup the 'Opportunity' object to pull the Opportunity Name. I also need to grab the name of whoever the task is assigned to (using OwnerID) but I'm not sure what object to link to to get it.
Any pointers would help!
Thank you!
Any pointers would help!
public with sharing class SlackNewTaskPublisher { private static final String slackURL = 'https://hooks.slack.com/services/abcde'; public class Tasky { @InvocableVariable(label='Subject') public String subject; @InvocableVariable(label='AccountID') public String oppname; @InvocableVariable(label='ActivityDate') public String duedate; @InvocableVariable(label='OwnerId') public String assignedto; } @InvocableMethod(label='Post task to Slack') public static void postToSlack(List<Tasky> taskies) { Tasky o = taskies[0]; // If bulk, only post first to avoid overloading Slack channel Map<String,Object> msg = new Map<String,Object>(); msg.put('text', 'A new task has been added to: *' + o.oppname + '*\nTask: *' + o.subject + '*\nDue on ' + o.duedate + '\nAssigned To: ' + o.assignedto ); msg.put('mrkdwn', true); String body = JSON.serialize(msg); System.enqueueJob(new QueueableSlackCall(slackURL, 'POST', body)); } public class QueueableSlackCall implements System.Queueable, Database.AllowsCallouts { private final String url; private final String method; private final String body; public QueueableSlackCall(String url, String method, String body) { this.url = url; this.method = method; this.body = body; } public void execute(System.QueueableContext ctx) { HttpRequest req = new HttpRequest(); req.setEndpoint(url); req.setMethod(method); req.setBody(body); Http http = new Http(); HttpResponse res = http.send(req); } } }
Thank you!
So, for the msg.put statement, would the following be correct to display the opportunity name and username?