• Giussep Estrada
  • NEWBIE
  • 10 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 0
    Replies
Hi
I'm trying to integrate Salesforce with Slack and use InvocableMethod to enter some parameters on Process Builder 

Right now in the Process Builder I can only put the Message that is sent to slack but I also want to give the option to put the Webhook URL, right now the URL is set on the APEX Class but I want to give this option on the Process Builder so the admins can set this without going to the APEX class


I create and InvocableVariable but I don't know how to use it to send the Slack Weebhook URL
It's my first time working with InvocableMethods, any help would appreciated it :D
Here is my code so far:
public with sharing class SlackPublisher {
    private static final String slackURL = 'WEBHOOKURL';
    
    public class MessagePost {
        @InvocableVariable(label='Slack Message')
        public String postText;
        @InvocableVariable(label='Slack Webhook')
        public String slackWebhook;
    }
    
    @InvocableMethod(label='Post Simple Message to Slack')
    public static void postToSlack(List<MessagePost> msgs) {
        MessagePost p = msgs[0];   
        Map<String,Object> msg = new Map<String,Object>();
        msg.put('text', p.postText);
        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);
        }
    }
}

 
Hello guys
First post
I'm a newbie in Salesforce trying to understand how i can write test classes
I need to write a test class of the following class:
public class RelatedListEditController {
    @AuraEnabled( cacheable=true )  
    public static List < sObject > fetchRecords( String listValues ) {  
        List < String > strList = listValues.split( ',' );  
        if ( strList.size() >= 3 ) {  
            String recordId = strList.get( 0 );  
            String objectName = strList.get( 1 );  
            String parentFieldAPIName = strList.get( 2 );              
            String strSOQL = 'SELECT Id FROM ' + objectName + ' WHERE ' + parentFieldAPIName + ' = \'' + recordId + '\'' + ' WITH ' + 'SECURITY_ENFORCED';  
            strSOQL += ' LIMIT 20';
            return Database.query( strSOQL );  
        } else   
            return null;  
    }   
}
Any help would be appreciated
I just want to learn how i can do it