• Hermann Oure 6
  • NEWBIE
  • 20 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 12
    Questions
  • 6
    Replies
Hello,
I have created a class for Slack Notification and I would link to create a link to view the Question Post created on community.
I know it can be done via a custom label but that's exactly what I try to avoid.
The link should take me the the question post as seen below:

User-added image
The ideal would be to use Network class; that gets me close to what I need. For example "Network.getSelfRegUrl(myNetwork.id)" takes me correctly to support/s/register/...

User-added image
Network myNetwork = [SELECT Id FROM Network WHERE Name ='Smart Client Portal'];
		System.debug('MyDebug: ' +Network.getSelfRegUrl(myNetwork.id));
		//String fullRecordURL = URL.getSalesforceBaseUrl().toExternalForm() + '/' + myNetwork.Id;

        for(slackRequest r:requests){
            
            if(r.id != null && r.name != null && r.title != null) {
                System.debug('### SlackNotificationCommunityPosts new post');
                channelName = '#' +Label.Slack_Community_Channel;
                msg = 'A new community post has been created : *'+r.title+'* - By User : (*'+r.name+'*)';
                msg += '\nLink to Community post : '+Network.getSelfRegUrl(myNetwork.id)+'/'+r.id;
            }
But I cannot find any a way to get to 
support/s/question/...

User-added image

Is there a way to use Network class and get to support/s/question/...
Thank you

here is the whole code:
public class SlackNotificationCommunityPost {
    
    /*
    -------------------------------------------------------------------------------------------------
    -- - Description   : Class to send Slack notification based on QuestionPost created on Community
    -- -----------  ----  -------  ------------------------------------------------------------------
     */
    
    public class slackRequest {
        @InvocableVariable(label='title')
        public String title; 
        
        @InvocableVariable(label='id')
        public String id; 
        
        @InvocableVariable(label='name')
        public String name;    
    }
    
    @InvocableMethod(label='Publish New Community posts to Slack')
    public static void publishNewCommunityPostsToSlack(List<slackRequest> requests) {

        //String webhookURL='https://hooks.slack.com/services/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';
        String webhookURL = system.label.Param_Slack_Token;
        String msg;
        String channelName;
        
        Network myNetwork = [SELECT Id FROM Network WHERE Name ='Smart Client Portal'];
		System.debug('MyDebug: ' +Network.getSelfRegUrl(myNetwork.id));
		//String fullRecordURL = URL.getSalesforceBaseUrl().toExternalForm() + '/' + myNetwork.Id;

        for(slackRequest r:requests){
            
            if(r.id != null && r.name != null && r.title != null) {
                System.debug('### SlackNotificationCommunityPosts new post');
                channelName = '#' +Label.Slack_Community_Channel;
                msg = 'A new community post has been created : *'+r.title+'* - By User : (*'+r.name+'*)';
                msg += '\nLink to Community post : '+Network.getSelfRegUrl(myNetwork.id)+'/'+r.id;
            }
            
            //Generate JSON for request
            try {
                if (r.id != null && r.title !=null && r.name != null) {
                   System.debug('### SlackNotificationCommunityPosts sending message');
                   JSONGenerator gen = JSON.createGenerator(true);
                    gen.writeStartObject(); //Inserts {
                    gen.writeStringField('text', msg);
                    gen.writeStringField('channel', '#salesforce_test');
                    gen.writeStringField('username', 'bot-support');
                    gen.writeStringField('icon_emoji', ':smartplus:');
                    gen.writeEndObject(); //Inserts }
                    String body = gen.getAsString(); //Translates JSONGenerator to string to be passed to callout
                    System.debug('### SlackNotificationCommunityPosts body: '+ body);
                    System.enqueueJob(new qCallOut(webhookURL, 'POST', body)); // Send request
      
               	 } else {
                    System.debug('### SlackNotificationCommunityPosts Id = '+ r.id);
                    return; 
                }
                
            }
            catch (exception e) {
                System.debug('### SlackNotificationCommunityPosts error:' +e);
            }
            
        }
     
    }
    
     public class qCallOut implements System.Queueable, Database.AllowsCallouts {
         
        private final String url;
        private final String method;
        private final String body;
         
        public qCallOut(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();
            // to pass when process builder is invoked by another test class
            if(!Test.isRunningTest()){  
              HttpResponse res = http.send(req);
            }
        }
         
     }

}


 
Hello,

I have created a class to send Slack notification to my community moderators anytime a Question Post is created in our Client Portal.
When clicking on the Link; The community moderator should be redirected to the post.
User-added imageBut I am not able to redirect to the community. I would rather not use a custom label.
I would prefer using the Network Id of the community or if there is something similar to "URL.getOrgDomainUrl().toExternalForm()":
User-added imageMy current code uses a custom label but I really don't want to use a custom label.
public class SlackNotificationCommunityPost {
    
    /*
    -------------------------------------------------------------------------------------------------
    -- - Description   : Class to send Slack notification based on QuestionPost created on Community
    -- -----------  ----  -------  ------------------------------------------------------------------
     */
    
    public class slackRequest {
        @InvocableVariable(label='title')
        public String title; 
        
        @InvocableVariable(label='id')
        public String id; 
        
        @InvocableVariable(label='name')
        public String name;    
    }
    
    @InvocableMethod(label='Publish New Community posts to Slack')
    public static void publishNewCommunityPostsToSlack(List<slackRequest> requests) {

        //String webhookURL='https://hooks.slack.com/services/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';
        String webhookURL = system.label.Param_Slack_Token;
        String msg;
        String channelName;

        for(slackRequest r:requests){
            
            if(r.id != null && r.name != null && r.title != null) {
                System.debug('### SlackNotificationCommunityPosts new post');
                channelName = '#' +Label.Slack_Community_Channel;
                msg = 'A new community post has been created : *'+r.title+'* - By User : (*'+r.name+'*)';
                msg += '\nLink to Community post : '+Label.Smart_Client_Portal+'/'+r.id;
            }
            
            //Generate JSON for request
            try {
                if (r.id != null && r.title !=null && r.name != null) {
                   System.debug('### SlackNotificationCommunityPosts sending message');
                   JSONGenerator gen = JSON.createGenerator(true);
                    gen.writeStartObject(); //Inserts {
                    gen.writeStringField('text', msg);
                    gen.writeStringField('channel', '#salesforce_test');
                    gen.writeStringField('username', 'bot-support');
                    gen.writeStringField('icon_emoji', ':smartplus:');
                    gen.writeEndObject(); //Inserts }
                    String body = gen.getAsString(); //Translates JSONGenerator to string to be passed to callout
                    System.debug('### SlackNotificationCommunityPosts body: '+ body);
                    System.enqueueJob(new qCallOut(webhookURL, 'POST', body)); // Send request
      
               	 } else {
                    System.debug('### SlackNotificationCommunityPosts Id = '+ r.id);
                    return; 
                }
                
            }
            catch (exception e) {
                System.debug('### SlackNotificationCommunityPosts error:' +e);
            }
            
        }
     
    }
    
     public class qCallOut implements System.Queueable, Database.AllowsCallouts {
         
        private final String url;
        private final String method;
        private final String body;
         
        public qCallOut(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();
            // to pass when process builder is invoked by another test class
            if(!Test.isRunningTest()){  
              HttpResponse res = http.send(req);
            }
        }
         
     }

}
Thank you.
 
Hello,

I would like to automatically update categories when creating an Article.
When creating a Known Error article. 
User-added imageI would like the catgories to be automatically updated to known error categories.
User-added image
At the moment, I have to do it manually.
User-added imageAnyone has an Idea on how I could go about automating the process?
Thanks,
Hermann
Hello,

I am trying to update the value of a custom field on all cases that counts the number of interactions (FeedItem =='textPost') with clients.
Everything works fine on the sandbox but when trying to replicate the query on Prod.
I have the following error:
User-added imageHere is my query on the anonymous window
update [SELECT id FROM FeedItem WHERE type = 'textPost' LIMIT 10000];

How can I solved this issue?
Thanks

Please see also my trigger:
trigger FeedItemTrigger on FeedItem (after insert, after update, before delete) {
    if(Trigger.isAfter){
        if(Trigger.isInsert || Trigger.isUpdate){
          List<FeedItem> caseFeedItems = new  List<FeedItem>();
            for(feedItem f: trigger.new) {
                if(String.valueOf(f.parentId).startsWith('500')){
                    caseFeedItems.add(f);
                }
            } 
            if(caseFeedItems.size()>0)FeedItemTriggerHandler.countFeedItem(caseFeedItems);    
        }
    } else if(Trigger.isBefore){
      if(Trigger.isDelete){
          List<FeedItem> caseFeedItems = new List<FeedItem>();
          for(feedItem f: trigger.old) {
              if(String.valueOf(f.ParentId).StartsWith('500'))
                  caseFeedItems.add(f);
          }   
        }
    }
}


 
Hi,
My apex code doesn't not increment the count. Can't find out Why.
Could someone help?
Thanks
Apex class:
public class FeedItemTriggerHandler {
    public static void countFeedItem(List<FeedItem> lstFeed){ 
        set<id> relatedCasesIds = new set<id>();
        for(FeedItem fd : lstFeed) {
            if (fd.type =='TextPost')relatedCasesIds.add(fd.ParentId);
        }
        Map<Id, case> relatedCases = new Map<Id, case> ([Select id, caseNumber,All_Users_Feed_Count__c FROM case where id in: relatedCasesIds]);
       	List<case> casesToUpdate = new List<case>(); 
        
        integer count = 0;
        for(case c:relatedCases.values()) {
           for(FeedItem fd : lstFeed) {
               if (fd.type =='TextPost' && fd.Visibility =='AllUsers' && fd.ParentId == c.id) {
                   count+=1;
                   
               } 
       		 } 
            c.All_Users_Feed_Count__c = count;
            count = 0;
            casesToUpdate.add(c);
              
        }
        if(casesToUpdate.size() > 0) update casesToUpdate; 
    }
}
Trigger:
trigger FeedItemTrigger on FeedItem (after insert,before delete) {
    if(Trigger.isAfter){
        if(Trigger.isInsert){
          FeedItemTriggerHandler.countFeedItem(Trigger.new);    
        }
    } else if(Trigger.isBefore){
      if(Trigger.isDelete){
          FeedItemTriggerHandler.countFeedItem(Trigger.old);    
        }
    }
}



 
Hello,

I have created an apex class to count the number of textpost in a case but my code doesn't not iterate...
Could someone help?
Thanks
public class FeedItemTriggerHandler {
    public static void countFeedItem(List<FeedItem> lstFeed){ 
        set<id> relatedCasesIds = new set<id>();
        for(FeedItem fd : lstFeed) {
            if (fd.type =='TextPost')relatedCasesIds.add(fd.ParentId);
        }
        Map<Id, case> relatedCases = new Map<Id, case> ([Select id, caseNumber,All_Users_Feed_Count__c FROM case where id in: relatedCasesIds]);
       	List<case> casesToUpdate = new List<case>(); 
        
        integer count = 0;
        for(case c:relatedCases.values()) {
           for(FeedItem fd : lstFeed) {
               if (fd.type =='TextPost' && fd.Visibility =='AllUsers' && fd.ParentId == c.id) {
                   count+=1;
                   
               } 
       		 } 
            c.All_Users_Feed_Count__c = count;
            count = 0;
            casesToUpdate.add(c);
              
        }
        if(casesToUpdate.size() > 0) update casesToUpdate; 
    }
}

 
Hello,

I have created an Apex class to count the number of interactions between the customer and the team when Feed Item Type = 'TextPost' or 'EmailMessageEvent'
My custom field "All Users Feed Count" increments correctly when a feed item Text Post is created but it doesn't increment for the Email Feed.
User-added image

Could someone help?
Thanks.

here is my code: 
public class FeedItemTriggerHandler {
    public static void countFeedItem(List<FeedItem> lstFeed){
        if(lstFeed.size() > 0){
            set<Id> setParentIds = new Set<Id>();
            for(FeedItem fd : lstFeed){
                setParentIds.add(fd.ParentId);
            }
            if(setParentIds.size() > 0){
                List<Case> lstCase = [Select caseNumber,All_Users_Feed_Count__c, (Select Id,body,Type,Visibility From Feeds where Type = 'TextPost' OR Type = 'EmailMessageEvent') From Case where Id In : setParentIds];
                if(lstCase.size() > 0){
                    for(Case cs : lstCase){
                        List<CaseFeed> feeds = cs.feeds;
                        Integer count = 0;
                        for(CaseFeed cf : feeds){
                            if(cf.Visibility == 'AllUsers'){
                                count+=1;    
                            }
                        }
                        System.debug(feeds.size());
                        cs.All_Users_Feed_Count__c = count;
                    }
                    update lstCase;
                }    
            }
        }
    }
}

 
Hello,

I am trying to create a roll up summary field on cases for Feed Item ID.
Basically I am trying to track the percentage of case solved with less or 2 interactions with clients.

But I am unable to access Feed Item for the object case feed.
Is there a way to do it without using the appexchange.

Thanks.
User-added image
Hello,

I would like to create a backlog report / dashboard that compare the number of cases that are (In progress / escalated) against the number of cases closed on a daily basis.
My cases status are as follow:
New
In progress
Escalated
Closed

I have created a dashboard showing me the correct record count but I am unable to sort it by date.
User-added imageAnd when trying with a case history report. I am unable to have the correct record count for In progress / Escalated / Closed cases.

Ideally, I am trying to have a backlog report showing my cases 
In progress
Escalated
Closed
Something similar to the report below but instead of created / closed, I need to be able to show: In progress - Escalated -  Closed
User-added imageAny pointers on how I could create this type of report / dashboard?

Thank you,
Hermann
Hi,

I would like to be able to mention users with @mention in my custom feed quick action 

I have created a lightning quick action called "Coworking Comm" on case feed so Company users can communicate internally on cases of certain type that we call "coworking cases".

And I would like for any user to tag or mention another user. Similar to the post feed as shown below:

Thank you
User-added image
I would like to replicate the same thing with @mention in "coworking comm" quick action.
User-added image


here is are my codes:

<--- .cmp: --->
<aura:component controller="CoworkingComm" implements="flexipage:availableForRecordHome,force:hasRecordId,force:lightningQuickAction" access="global" >
    
    <aura:attribute name="recordId" type="Id" />
    <aura:attribute name="textPost" type="String" />
    <aura:attribute name="thisCase" type="Case" default="{ 'sobjectType': 'Case' }"/> 
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
    
    <div class="coworking_comm">
            <lightning:inputRichText variant="bottom-toolbar" value="{!v.textPost}" formats="['bold','italic','underline','strike','list','clean']" shareWithEntityId="{!v.recordId}">
                <lightning:insertImageButton />             
            </lightning:inputRichText>            
        </div>
    <div class="coworking_comm"><lightning:button label="Share" onclick="{!c.shareComm }"/></div>
    
 </aura:component>

<--- controller.js: --->
({
    doInit: function(cmp) {
             
        cmp.set('v.textPost', '<p><script>alert(this)</script></p><p>hi!</p>');
        
    },
    
    shareComm : function (component, event, helper) {
        var action = component.get("c.ctrlShareComm");
            action.setParams({
                caseid: component.get("v.recordId"),
                textPost: component.get("v.textPost")
                
            });
            
             //force refresh of the page
                action.setCallback(this, function(data) {
                var result = data.getReturnValue();
                $A.get('e.force:refreshView').fire();
                
            });
         //Queue the action
            $A.enqueueAction(action);
        
    },
    
});

<--- controller.apxc: --->
public with sharing class CoworkingComm {
@AuraEnabled
    public static Case getCase(string caseid){
        Case c = [SELECT Id,Status,Owner.Type,First_Reply_Date__c FROM Case WHERE Id=:caseid LIMIT 1];
        return c;
    }
    @AuraEnabled
    public static string ctrlShareComm (String caseid, String textPost)
    {
        string result = 'success';        
              
        // REMOVE BR FROM TEXTPOST
        textPost = textPost.replaceAll('<br>','<p>&nbsp;</p>');
        textPost = textPost.replaceAll('strike>','s>');
        
        // CREATE FEED ITEM AND POST IT
        FeedItem post = new FeedItem();
        post.ParentId = caseid;
        post.IsRichText = true;
        post.type = 'LinkPost'; 
        post.Body = textPost;
        post.Visibility = 'InternalUsers';
                              
        try{
            insert post;
            //ConnectApi.FeedElement feedElement = ConnectApi.ChatterFeeds.postFeedElement('InternalUsers',caseid,ConnectApi.FeedElementType.FeedItem,textPost);
        }
        catch(Exception e)
        {
            System.debug('CoworkingCommunicationController - Error inserting post');
            return 'post_error';
        }
        return 'case_error';
    }
}

Hello,

I would like to create an action called "Coworking" with the exact same attributes to Post (under feed) to share update only related to my coworking cases 

Basically I would like my quick action to have the exact same features / toolbar as we see on the Post action (e.g bold, italic, underline...)

Does someone knows how to do it?
Thanks,
Hermann

User-added image

Hello,

I would like to stop customer interaction on cases with status closed.
Basically when we click on the button "close case" or when we change the satus of a case to "closed".
I would like to stop the customer from making any update in this case.

Such a sharing an update with the share button or "Raise a Concern" by clicking on the button. 
If all the buttons or the whole page could be disabled or put on read only. So it is not possible for a customer to interact with a closed case anymore.

If anyone has a sample code, that would be great.
Thank you.
User-added image

User-added image

Hello,
I have created a class for Slack Notification and I would link to create a link to view the Question Post created on community.
I know it can be done via a custom label but that's exactly what I try to avoid.
The link should take me the the question post as seen below:

User-added image
The ideal would be to use Network class; that gets me close to what I need. For example "Network.getSelfRegUrl(myNetwork.id)" takes me correctly to support/s/register/...

User-added image
Network myNetwork = [SELECT Id FROM Network WHERE Name ='Smart Client Portal'];
		System.debug('MyDebug: ' +Network.getSelfRegUrl(myNetwork.id));
		//String fullRecordURL = URL.getSalesforceBaseUrl().toExternalForm() + '/' + myNetwork.Id;

        for(slackRequest r:requests){
            
            if(r.id != null && r.name != null && r.title != null) {
                System.debug('### SlackNotificationCommunityPosts new post');
                channelName = '#' +Label.Slack_Community_Channel;
                msg = 'A new community post has been created : *'+r.title+'* - By User : (*'+r.name+'*)';
                msg += '\nLink to Community post : '+Network.getSelfRegUrl(myNetwork.id)+'/'+r.id;
            }
But I cannot find any a way to get to 
support/s/question/...

User-added image

Is there a way to use Network class and get to support/s/question/...
Thank you

here is the whole code:
public class SlackNotificationCommunityPost {
    
    /*
    -------------------------------------------------------------------------------------------------
    -- - Description   : Class to send Slack notification based on QuestionPost created on Community
    -- -----------  ----  -------  ------------------------------------------------------------------
     */
    
    public class slackRequest {
        @InvocableVariable(label='title')
        public String title; 
        
        @InvocableVariable(label='id')
        public String id; 
        
        @InvocableVariable(label='name')
        public String name;    
    }
    
    @InvocableMethod(label='Publish New Community posts to Slack')
    public static void publishNewCommunityPostsToSlack(List<slackRequest> requests) {

        //String webhookURL='https://hooks.slack.com/services/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';
        String webhookURL = system.label.Param_Slack_Token;
        String msg;
        String channelName;
        
        Network myNetwork = [SELECT Id FROM Network WHERE Name ='Smart Client Portal'];
		System.debug('MyDebug: ' +Network.getSelfRegUrl(myNetwork.id));
		//String fullRecordURL = URL.getSalesforceBaseUrl().toExternalForm() + '/' + myNetwork.Id;

        for(slackRequest r:requests){
            
            if(r.id != null && r.name != null && r.title != null) {
                System.debug('### SlackNotificationCommunityPosts new post');
                channelName = '#' +Label.Slack_Community_Channel;
                msg = 'A new community post has been created : *'+r.title+'* - By User : (*'+r.name+'*)';
                msg += '\nLink to Community post : '+Network.getSelfRegUrl(myNetwork.id)+'/'+r.id;
            }
            
            //Generate JSON for request
            try {
                if (r.id != null && r.title !=null && r.name != null) {
                   System.debug('### SlackNotificationCommunityPosts sending message');
                   JSONGenerator gen = JSON.createGenerator(true);
                    gen.writeStartObject(); //Inserts {
                    gen.writeStringField('text', msg);
                    gen.writeStringField('channel', '#salesforce_test');
                    gen.writeStringField('username', 'bot-support');
                    gen.writeStringField('icon_emoji', ':smartplus:');
                    gen.writeEndObject(); //Inserts }
                    String body = gen.getAsString(); //Translates JSONGenerator to string to be passed to callout
                    System.debug('### SlackNotificationCommunityPosts body: '+ body);
                    System.enqueueJob(new qCallOut(webhookURL, 'POST', body)); // Send request
      
               	 } else {
                    System.debug('### SlackNotificationCommunityPosts Id = '+ r.id);
                    return; 
                }
                
            }
            catch (exception e) {
                System.debug('### SlackNotificationCommunityPosts error:' +e);
            }
            
        }
     
    }
    
     public class qCallOut implements System.Queueable, Database.AllowsCallouts {
         
        private final String url;
        private final String method;
        private final String body;
         
        public qCallOut(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();
            // to pass when process builder is invoked by another test class
            if(!Test.isRunningTest()){  
              HttpResponse res = http.send(req);
            }
        }
         
     }

}


 
Hello,

I have created a class to send Slack notification to my community moderators anytime a Question Post is created in our Client Portal.
When clicking on the Link; The community moderator should be redirected to the post.
User-added imageBut I am not able to redirect to the community. I would rather not use a custom label.
I would prefer using the Network Id of the community or if there is something similar to "URL.getOrgDomainUrl().toExternalForm()":
User-added imageMy current code uses a custom label but I really don't want to use a custom label.
public class SlackNotificationCommunityPost {
    
    /*
    -------------------------------------------------------------------------------------------------
    -- - Description   : Class to send Slack notification based on QuestionPost created on Community
    -- -----------  ----  -------  ------------------------------------------------------------------
     */
    
    public class slackRequest {
        @InvocableVariable(label='title')
        public String title; 
        
        @InvocableVariable(label='id')
        public String id; 
        
        @InvocableVariable(label='name')
        public String name;    
    }
    
    @InvocableMethod(label='Publish New Community posts to Slack')
    public static void publishNewCommunityPostsToSlack(List<slackRequest> requests) {

        //String webhookURL='https://hooks.slack.com/services/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';
        String webhookURL = system.label.Param_Slack_Token;
        String msg;
        String channelName;

        for(slackRequest r:requests){
            
            if(r.id != null && r.name != null && r.title != null) {
                System.debug('### SlackNotificationCommunityPosts new post');
                channelName = '#' +Label.Slack_Community_Channel;
                msg = 'A new community post has been created : *'+r.title+'* - By User : (*'+r.name+'*)';
                msg += '\nLink to Community post : '+Label.Smart_Client_Portal+'/'+r.id;
            }
            
            //Generate JSON for request
            try {
                if (r.id != null && r.title !=null && r.name != null) {
                   System.debug('### SlackNotificationCommunityPosts sending message');
                   JSONGenerator gen = JSON.createGenerator(true);
                    gen.writeStartObject(); //Inserts {
                    gen.writeStringField('text', msg);
                    gen.writeStringField('channel', '#salesforce_test');
                    gen.writeStringField('username', 'bot-support');
                    gen.writeStringField('icon_emoji', ':smartplus:');
                    gen.writeEndObject(); //Inserts }
                    String body = gen.getAsString(); //Translates JSONGenerator to string to be passed to callout
                    System.debug('### SlackNotificationCommunityPosts body: '+ body);
                    System.enqueueJob(new qCallOut(webhookURL, 'POST', body)); // Send request
      
               	 } else {
                    System.debug('### SlackNotificationCommunityPosts Id = '+ r.id);
                    return; 
                }
                
            }
            catch (exception e) {
                System.debug('### SlackNotificationCommunityPosts error:' +e);
            }
            
        }
     
    }
    
     public class qCallOut implements System.Queueable, Database.AllowsCallouts {
         
        private final String url;
        private final String method;
        private final String body;
         
        public qCallOut(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();
            // to pass when process builder is invoked by another test class
            if(!Test.isRunningTest()){  
              HttpResponse res = http.send(req);
            }
        }
         
     }

}
Thank you.
 
Hi,
My apex code doesn't not increment the count. Can't find out Why.
Could someone help?
Thanks
Apex class:
public class FeedItemTriggerHandler {
    public static void countFeedItem(List<FeedItem> lstFeed){ 
        set<id> relatedCasesIds = new set<id>();
        for(FeedItem fd : lstFeed) {
            if (fd.type =='TextPost')relatedCasesIds.add(fd.ParentId);
        }
        Map<Id, case> relatedCases = new Map<Id, case> ([Select id, caseNumber,All_Users_Feed_Count__c FROM case where id in: relatedCasesIds]);
       	List<case> casesToUpdate = new List<case>(); 
        
        integer count = 0;
        for(case c:relatedCases.values()) {
           for(FeedItem fd : lstFeed) {
               if (fd.type =='TextPost' && fd.Visibility =='AllUsers' && fd.ParentId == c.id) {
                   count+=1;
                   
               } 
       		 } 
            c.All_Users_Feed_Count__c = count;
            count = 0;
            casesToUpdate.add(c);
              
        }
        if(casesToUpdate.size() > 0) update casesToUpdate; 
    }
}
Trigger:
trigger FeedItemTrigger on FeedItem (after insert,before delete) {
    if(Trigger.isAfter){
        if(Trigger.isInsert){
          FeedItemTriggerHandler.countFeedItem(Trigger.new);    
        }
    } else if(Trigger.isBefore){
      if(Trigger.isDelete){
          FeedItemTriggerHandler.countFeedItem(Trigger.old);    
        }
    }
}



 
Hello,

I have created an apex class to count the number of textpost in a case but my code doesn't not iterate...
Could someone help?
Thanks
public class FeedItemTriggerHandler {
    public static void countFeedItem(List<FeedItem> lstFeed){ 
        set<id> relatedCasesIds = new set<id>();
        for(FeedItem fd : lstFeed) {
            if (fd.type =='TextPost')relatedCasesIds.add(fd.ParentId);
        }
        Map<Id, case> relatedCases = new Map<Id, case> ([Select id, caseNumber,All_Users_Feed_Count__c FROM case where id in: relatedCasesIds]);
       	List<case> casesToUpdate = new List<case>(); 
        
        integer count = 0;
        for(case c:relatedCases.values()) {
           for(FeedItem fd : lstFeed) {
               if (fd.type =='TextPost' && fd.Visibility =='AllUsers' && fd.ParentId == c.id) {
                   count+=1;
                   
               } 
       		 } 
            c.All_Users_Feed_Count__c = count;
            count = 0;
            casesToUpdate.add(c);
              
        }
        if(casesToUpdate.size() > 0) update casesToUpdate; 
    }
}