• Ricky_Theda
  • NEWBIE
  • 25 Points
  • Member since 2015
  • Consultant

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 8
    Replies
public class SlackOpportunityPublisher {
    private static final String slackURL = 'https://hooks.slack.com/services/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';
    
    public class Id {
        @InvocableVariable(label='Opportunity Name')
        public String opptyName;
        @InvocableVariable(label='Type')
        public String Type;
        @InvocableVariable(label='Stage')
        public String stage;
        @InvocableVariable(label='Probability')
        public String probability;
        @InvocableVariable(label='First')
        public string first;
        @InvocableVariable(label='Last')
        public string last;
        @InvocableVariable(label='Close')
        public string close;                 
    }
    @InvocableMethod(label='Post to Slack')
    public static void postToSlack(List<Id> opportunityId) {
        Id oppId = opportunityId[0]; // If bulk, only post first to avoid overloading Slack channel
        Opportunity opportunity = [SELECT Name, Type, StageName, Probability, Owner.FirstName, Owner.LastName, CloseDate from Opportunity WHERE id=:OPPid];
        Map<String,Object> msg = new Map<String,Object>();
        msg.put('text', 'The following opportunity has changed:\n' + 'Account Name And Product: ' + Opportunity.Name + '\nType: ' + opportunity.Type + '\nNew Stage: ' + opportunity.StageName + '\nSales Person: ' + opportunity.Owner.FirstName + ' ' + opportunity.Owner.LastName + '\nProbability: ' + opportunity.Probability + '%' + '\nForcasted Close Date: ' + opportunity.CloseDate);
        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();
            if (!Test.isRunningTest()) { // HTTP callout is not allowed in tests apparently...
            HttpResponse res = http.send(req);
        }
    }
    }
}
@isTest
private class SlackOpportunityPublisherTest{
    static testMethod void testPostToSlack() {
        SlackOpportunityPublisher.Id pubTest = new SlackOpportunityPublisher.Id();
        pubTest.opptyName = 'Test opportunity';
        pubTest.type = 'Test Type';
        pubTest.stage = 'Test stage';
        pubtest.probability = 'Test probability';
        pubTest.first = 'Test First';
        pubTest.last = 'Test Last';
        pubTest.close = 'Test Close';
        List<SlackOpportunityPublisher.Id> theList = new List<SlackOpportunityPublisher.Id>();
        theList.add(pubTest);
        SlackOpportunityPublisher.postToSlack(theList);
        System.assertEquals(theList, theList); // Can't really test this, just put something that is true
    }
}
Any help is appriciated this is the problem Method does not exist or incorrect signature: void postToSlack(List<SlackOpportunityPublisher.Id>) from the type SlackOpportunityPublisher
Just heard some rumour from my collague that Salesforce for facebook and twitter from appexchange will not be supported anymore. What if my customer already installed and used it? Does salesforce prepare another free apps in exchange?
public class SlackOpportunityPublisher {
    private static final String slackURL = 'https://hooks.slack.com/services/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';
    
    public class Id {
        @InvocableVariable(label='Opportunity Name')
        public String opptyName;
        @InvocableVariable(label='Type')
        public String Type;
        @InvocableVariable(label='Stage')
        public String stage;
        @InvocableVariable(label='Probability')
        public String probability;
        @InvocableVariable(label='First')
        public string first;
        @InvocableVariable(label='Last')
        public string last;
        @InvocableVariable(label='Close')
        public string close;                 
    }
    @InvocableMethod(label='Post to Slack')
    public static void postToSlack(List<Id> opportunityId) {
        Id oppId = opportunityId[0]; // If bulk, only post first to avoid overloading Slack channel
        Opportunity opportunity = [SELECT Name, Type, StageName, Probability, Owner.FirstName, Owner.LastName, CloseDate from Opportunity WHERE id=:OPPid];
        Map<String,Object> msg = new Map<String,Object>();
        msg.put('text', 'The following opportunity has changed:\n' + 'Account Name And Product: ' + Opportunity.Name + '\nType: ' + opportunity.Type + '\nNew Stage: ' + opportunity.StageName + '\nSales Person: ' + opportunity.Owner.FirstName + ' ' + opportunity.Owner.LastName + '\nProbability: ' + opportunity.Probability + '%' + '\nForcasted Close Date: ' + opportunity.CloseDate);
        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();
            if (!Test.isRunningTest()) { // HTTP callout is not allowed in tests apparently...
            HttpResponse res = http.send(req);
        }
    }
    }
}
@isTest
private class SlackOpportunityPublisherTest{
    static testMethod void testPostToSlack() {
        SlackOpportunityPublisher.Id pubTest = new SlackOpportunityPublisher.Id();
        pubTest.opptyName = 'Test opportunity';
        pubTest.type = 'Test Type';
        pubTest.stage = 'Test stage';
        pubtest.probability = 'Test probability';
        pubTest.first = 'Test First';
        pubTest.last = 'Test Last';
        pubTest.close = 'Test Close';
        List<SlackOpportunityPublisher.Id> theList = new List<SlackOpportunityPublisher.Id>();
        theList.add(pubTest);
        SlackOpportunityPublisher.postToSlack(theList);
        System.assertEquals(theList, theList); // Can't really test this, just put something that is true
    }
}
Any help is appriciated this is the problem Method does not exist or incorrect signature: void postToSlack(List<SlackOpportunityPublisher.Id>) from the type SlackOpportunityPublisher
Good Evening, 

I am using AggregateResult and GROUP BY ROLLUP to output some data.  After a long slog, I've got it working the way I need it to... except for one thing.  The "Total" row is showing at the top of the list instead of the bottom when I put the data into a table. 

Would anybody be able to help me get my total row so that it is the last item in the table?

Here is my VF page: 
<apex:page controller="CurrentWeekDY">
 
 <apex:pageBlock title="Delivery WTD">
 <apex:pageBlockTable value="{!DelSumOut}" var="dy">
   <apex:column value="{!dy.Campaign}" headerValue="Campaign" />
   <apex:column value="{!dy.Delivery}" headerValue="Delivery" />  
 
 </apex:pageBlockTable>
 </apex:pageBlock>
 
 

And here is my controller: 
public class CurrentWeekDY {
    public class DelSum {
        public String Campaign {get; set;}
        public String Delivery {get; set;}

        public DelSum(string c, string d) {
            this.Campaign = c;
            this.Delivery = d;
        }
    }

    public List<DelSum> DelSumList = new List<DelSum>();

    public List<DelSum> getDelSumOut() {
        AggregateResult[] AgR = [SELECT Camp__c, SUM(Spend__c) FROM TL_Client__c WHERE CWDelivery__c = TRUE GROUP BY ROLLUP(Camp__c) ORDER BY Camp__c];

        for (AggregateResult DYList : AgR) {
            DelSumList.add(new DelSum(String.valueOf(DYList.get('Camp__c')), String.valueOf(DYList.get('expr0'))));
        }

        return DelSumList;
    }
}


I would really appreciate any help!!

Thanks, 
 

John 

I am new to Apex trigger/class coding.  I was able to create a simple trigger that works, but I am having trouble with code coverage and can't roll it to the production environment.  I would appreciate any help with Apex Class coding.  (or could you point me toward a tutorial?) Thank you in advance.

My trigger is as follows:

trigger WorkstreamStamp on Project__c (before insert) {
    For(Project__c p : Trigger.New)
    {
         If(p.Workstream__c == null)
         {
           List<Account> incomingprojinfo = [Select Workstream__c FROM  Account WHERE Id =:p.Sponsor_Account_Ultimate_Parent__c LIMIT 1];
                               {
               p.Workstream__c = incomingprojinfo[0].Workstream__c;
           }                                                      
          
         }
       
    }                           
}
  • January 18, 2018
  • Like
  • 0