• Jean-Sebastien Dorais
  • NEWBIE
  • 10 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 1
    Replies
All,

I'm stumped and reaching out to the community.

I'm trying to create a formula that will display a date based on TODAY().  Here are the criterias:
  • If TODAY() is between January 1 and April 30, set the date to TODAY() + 15 days of the CURRENT year
  • If TODAY() is between May 1 and December 31, set the date to February 1 of NEXT year
Any pointers are appreciated!
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!
 
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!
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!
 
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!