• Bundit Phetplay 15
  • NEWBIE
  • 10 Points
  • Member since 2017

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

Dear All,

Here is my requirement

- Capture All of Approver comment of each step

- Display the previous approver and below the layer to the approver in email (For example if approver in step 4., He wants to see the comment from step 1 2 and 3 'without' open the SFDC record <--- This point I aim to capture the comment and send the email)

My problem is my very simple trigger works only at the end of the approval process with only lastest comment, I try to add 'Field Update' action to '1st Approvers Approve' but it's not working, Can anyone can suggest me or revise my code? (Maximum of my approval layer is 5)

Here is my very simple trigger

Note that copy_comment__c is a checkbox field to fire a trigger via the approval process

and Approver_Comment__c is a field to keep the comment (maybe I need to create 4 more of this fields to stamp all of 5 approver's comment)

trigger TriggerApprover on Quote (before update) {
    
       if(trigger.isUpdate){
             List<Quote> QuoList =  [Select id,
                                                   (Select Id, 
                                                         IsPending, 
                                                         ProcessInstanceId, 
                                                         TargetObjectId, 
                                                         StepStatus, 
                                                         OriginalActorId, 
                                                         ActorId, 
                                                         RemindersSent, 
                                                         Comments, 
                                                         IsDeleted, 
                                                         CreatedDate, 
                                                         CreatedById, 
                                                         SystemModstamp 
                                                    FROM ProcessSteps
                                                ORDER BY CreatedDate DESC) 
                                                    From Quote
                                                WHERE Id IN : Trigger.new];

             if(QuoList.size() > 0){

               for(Quote quo : QuoList){
              
                for(Quote quo1 : Trigger.new) {
                  
                         //check copy comment is true
                         if(quo.id == quo1.id && quo1.copy_comment__c ) {
 
                           if (quo.ProcessSteps.size() > 0) {
                            
                         quo1.Approver_Comment__c = quo.ProcessSteps[0].Comments;
                         quo1.copy_comment__c = false;
                
                           }

                        }
                 
                    }
               }
             }   
        }  
    }

Hi Developers,

I'm from the functional side and this is my first time to write the trigger and test class

Here is the requirement that I got 'Once user tag me or manager in Chatter Feed --> Create Case with getting the information of where chatter feed has been posted'

I separated into 2 triggers

1.Create_CaseComment_From_Chatter

trigger Create_CaseComment_From_Chatter on FeedComment (before insert) { 

List<Chatter_Case_Reply__c> lstCase = new List<Chatter_Case_Reply__c>(); //Creating a list to save the comments section in the related list  
Set<Id> feedItemsId = new Set<Id>(); 

// Get ParentId from feeditem and create a map of feed items 
for (FeedComment f: Trigger.new) 
feedItemsId.add(f.feedItemId); 
Map<Id,FeedItem> fitems = new Map<Id,FeedItem>([Select id, Parentid from feedItem where id in :feedItemsId]); 


for (FeedComment f: Trigger.new) 
{ 
if(String.valueof(f.CommentBody) != '') 
{ 
Chatter_Case_Reply__c newCase = new Chatter_Case_Reply__c(); 
newCase.Comments__c = f.CommentBody; 

Id parId = fitems.get(f.feedItemId).ParentId; 
SObjectType sobType = parId.getSObjectType(); 
if (sobType == Case.SObjectType) { 
newCase.Case__c = parId; 
} 

lstCase.add(newCase); 
} 

} 
insert lstCase; 

}


2.ReplaceCharANDIsAssign <-- using for replacing some char to make it easier to read the case record

trigger ReplaceCharANDIsAssign on Case (before insert,before update) {
for(Case c : Trigger.new){
c.Description = c.Description.replaceAll('\\<.*?\\>', ' ');
c.Description = c.Description.replaceAll('&nbsp;', ' ');
c.Desc__c = c.Desc__c.replaceAll('\\<.*?\\>', ' ');
c.Desc__c = c.Desc__c.replaceAll('&nbsp;', ' ');
c.Description = c.Description.replaceAll('@Bundit Phetplay', '');
c.Description = c.Description.replaceAll('@Wuttisak Thabthimsaen', '');
c.Description = c.Description.replaceAll('@Thabthimsaen Wuttisak', '');
c.Description = c.Description.replaceAll('@Phetplay Bundit', '');
//c.Description = c.Description.replaceAll('#caseoth', ''); 
//c.Description = c.Description.replaceAll('#CASEOTH', ''); 
//c.Description = c.Description.replaceAll('#caseOTH', ''); 
//c.Description = c.Description.replaceAll('#CaseOth', '');
//c.Description = c.Description.replaceAll('#CaseOTH', '');  

if(String.valueof(c.Desc__c).Contains('Wuttisak')){
c.Is_assigned_to_Wuttisak__c = TRUE;
}

if(String.valueof(c.Desc__c).Contains('Bundit')){
c.Is_assigned_to_Bundit__c = TRUE;
}

}
}


My problem is I have no Idea how to write a test class for trigger '1.Create_CaseComment_From_Chatter' I only have 1 test class as the following

@isTest
private class testCreateCase {

static testMethod void mytestCreateCase() {

FeedItem post = new FeedItem();

post.ParentId = '0011000000oeLcH';
post.Body = '@Wuttisak Thabthimsaen @Bundit I need your help';

test.StartTest();
insert post;
test.StopTest();

    }
}

which coverage 100% on 2.ReplaceCharANDIsAssign trigger but 0% for the 1st trigger

If anyone has some advice or revise my test class would be appreciated!

Thank you

Dear All,

Here is my requirement

- Capture All of Approver comment of each step

- Display the previous approver and below the layer to the approver in email (For example if approver in step 4., He wants to see the comment from step 1 2 and 3 'without' open the SFDC record <--- This point I aim to capture the comment and send the email)

My problem is my very simple trigger works only at the end of the approval process with only lastest comment, I try to add 'Field Update' action to '1st Approvers Approve' but it's not working, Can anyone can suggest me or revise my code? (Maximum of my approval layer is 5)

Here is my very simple trigger

Note that copy_comment__c is a checkbox field to fire a trigger via the approval process

and Approver_Comment__c is a field to keep the comment (maybe I need to create 4 more of this fields to stamp all of 5 approver's comment)

trigger TriggerApprover on Quote (before update) {
    
       if(trigger.isUpdate){
             List<Quote> QuoList =  [Select id,
                                                   (Select Id, 
                                                         IsPending, 
                                                         ProcessInstanceId, 
                                                         TargetObjectId, 
                                                         StepStatus, 
                                                         OriginalActorId, 
                                                         ActorId, 
                                                         RemindersSent, 
                                                         Comments, 
                                                         IsDeleted, 
                                                         CreatedDate, 
                                                         CreatedById, 
                                                         SystemModstamp 
                                                    FROM ProcessSteps
                                                ORDER BY CreatedDate DESC) 
                                                    From Quote
                                                WHERE Id IN : Trigger.new];

             if(QuoList.size() > 0){

               for(Quote quo : QuoList){
              
                for(Quote quo1 : Trigger.new) {
                  
                         //check copy comment is true
                         if(quo.id == quo1.id && quo1.copy_comment__c ) {
 
                           if (quo.ProcessSteps.size() > 0) {
                            
                         quo1.Approver_Comment__c = quo.ProcessSteps[0].Comments;
                         quo1.copy_comment__c = false;
                
                           }

                        }
                 
                    }
               }
             }   
        }  
    }