+ Start a Discussion
Justin LonisJustin Lonis 

can anyone help me create a trigger to get "status" to change values (picklist field) from feed comments?

Just looking to have a status change from "Awaiting Customer Feedback" to "Working" when a Feed Comment post is made: A picture of the example is below. Any help would be appreciated!!!
!User-added imageThe top I did in process builder. The highlighted I'm having trouble with. 
Best Answer chosen by Justin Lonis
Sunil MadanaSunil Madana
Hi,
Ok thanks for the reply and the below code should solve the issue for you.
trigger CommentStatusUpd on FeedComment (after insert) {
	
    for (FeedComment feedcs : trigger.new){ 
        
        List<CaseFeed> chkCsFeed = [ SELECT Id FROM CaseFeed WHERE ParentId=: feedcs.ParentId ];
        if( chkCsFeed.size() > 0){
        	system.debug('***DEBUG***'+feedcs.ParentId);            
            List<Case> Pros = new List<Case>([ SELECT CaseNumber, Id, Status FROM Case WHERE Id =: feedcs.ParentId ]);
            for (integer i = 0; i < Pros.size(); i++){
                system.debug('***DEBUG-INFO: CaseId***'+Pros[i].Id);
            	system.debug('***DEBUG-INFO: CaseNumber***'+Pros[i].CaseNumber);
                system.debug('***DEBUG-INFO: CaseStatus***'+Pros[i].Status);
                Pros[i].Status = 'Working';
            }
            update Pros;
            
        }
        
	}
    
}
Thanks!!

All Answers

Sunil MadanaSunil Madana
Hi Justin,
Once a feed comment post is made, on which object / table do you want the update? Thanks.
 
Justin LonisJustin Lonis
Hi, 

So when this comment is made I would like the Case object updated. The field is just "status" the standard SF field. Any thoughts?

Thanks!!
Sunil MadanaSunil Madana
Hi,
Ok thanks for the reply and the below code should solve the issue for you.
trigger CommentStatusUpd on FeedComment (after insert) {
	
    for (FeedComment feedcs : trigger.new){ 
        
        List<CaseFeed> chkCsFeed = [ SELECT Id FROM CaseFeed WHERE ParentId=: feedcs.ParentId ];
        if( chkCsFeed.size() > 0){
        	system.debug('***DEBUG***'+feedcs.ParentId);            
            List<Case> Pros = new List<Case>([ SELECT CaseNumber, Id, Status FROM Case WHERE Id =: feedcs.ParentId ]);
            for (integer i = 0; i < Pros.size(); i++){
                system.debug('***DEBUG-INFO: CaseId***'+Pros[i].Id);
            	system.debug('***DEBUG-INFO: CaseNumber***'+Pros[i].CaseNumber);
                system.debug('***DEBUG-INFO: CaseStatus***'+Pros[i].Status);
                Pros[i].Status = 'Working';
            }
            update Pros;
            
        }
        
	}
    
}
Thanks!!
This was selected as the best answer
Justin LonisJustin Lonis
A quick comment....if I would like it where only external (maybe by profiles) could only be the ones where this will change the status how would I do that? 

So an example- if I'm an internal user (case owner) and I comment on the feed comment...I would not want it to change from awaiting customer feedback to working. 

Any assistance would be grately appreciated!

Thanks, 
Sunil MadanaSunil Madana
Hi Justin, Once this comment is made the given code will update the status as it updates only the Case Object (variable: "Pros"). Below code should update the Case status only if the profile is "Marketing User".
trigger CommentStatusUpd_906F0000000DA3tIAG on FeedComment (after insert) {
    for (FeedComment feedcs : trigger.new){
        List<CaseFeed> chkCsFeed = [ SELECT Id FROM CaseFeed WHERE ParentId=: feedcs.ParentId ];
        if( chkCsFeed.size() > 0){
            system.debug('***DEBUG***'+feedcs.ParentId);
            List<Case> Pros = new List<Case>([ SELECT CaseNumber, Id, Status, OwnerId FROM Case WHERE Id =: feedcs.ParentId ]);
            for (integer i = 0; i < Pros.size(); i++){
                List<User> Usrs = new List<User>([ SELECT ProfileId FROM User WHERE Id=: Pros[i].OwnerId ]);
                for (User usrprofile : Usrs) {
                    if( usrprofile.ProfileId == '00e90000001SIAI' ) {
                		Pros[i].Status = 'Working';        
                    }
                }
            }
            update Pros;
        }
    }
}
Let the group know once the above code works. Thanks.
Justin LonisJustin Lonis
Hi SF Issue-Fixer, 

So I put the following trigger in (I replaced the marketing user ID with another profile ID that should be able to have the status change and it won't change the status for anyone now :( 


trigger CommentStatusUpd_906F0000000DA3tIAG on FeedComment (after insert) {

    for (FeedComment feedcs : trigger.new){

        List<CaseFeed> chkCsFeed = [ SELECT Id FROM CaseFeed WHERE ParentId=: feedcs.ParentId ];

        if( chkCsFeed.size() > 0){

            system.debug('***DEBUG***'+feedcs.ParentId);

            List<Case> Pros = new List<Case>([ SELECT CaseNumber, Id, Status, OwnerId FROM Case WHERE Id =: feedcs.ParentId ]);

            for (integer i = 0; i < Pros.size(); i++){

                List<User> Usrs = new List<User>([ SELECT ProfileId FROM User WHERE Id=: Pros[i].OwnerId ]);

                for (User usrprofile : Usrs) {

                    if( usrprofile.ProfileId == '00e800000018sx8' ) {

                        Pros[i].Status = 'Working';       

                    }

                }

            }

            update Pros;

        }

    }

}
 
Justin LonisJustin Lonis
I didn't know if there was much different from the first trigger to the second one but I'll keep trying to plug in different profile ID's and see if I can get any of them to work. Unfortunately no luck though. Thanks in advance for your help!!!
Justin LonisJustin Lonis

Hi SF Issue-User, 

If you want check out this thread....there is some great stuff going on here (a continuation of our conversation on this thread). Can you help close out this issue for me? 

https://developer.salesforce.com/forums/ForumsMain?id=906F0000000DBeC