You need to sign in to do that
Don't have an account?
Charlotte Holden
FeedComment Apex Trigger to Update Field/Status depending on Profile Used to make Update
I'm hoping you clever people are able to help me please, as I do not know how to write Apex Code.
I have pulled the below from another post (which works), but need to adopt it for the following circumstances, and wondered whether someone might be able to help please:
trigger FeedThis on FeedComment(after insert, after update){
List<Case> updates = new List<case>();
List<id> userList = new List<ID>();
List<Id> feedItemList = new List<id>();
for(FeedComment fc: trigger.new){
feedItemList.add(fc.FeedItemId);
userList.add(fc.InsertedById);
}
Map<Id, FeedItem> feedMap = new Map<id, FeedItem>([select id,InsertedById,Visibility from feedItem where Id IN :feedItemList]);
Map<Id, User> userMap = new Map<Id, User>([select id, usertype, name from user where ID IN :userList]);
for(FeedComment fc: trigger.new){
if (feedMap != null && feedMap.containsKey(fc.feedItemId) && fc.ParentId.getSObjectType() == Case.SObjectType) {
updates.add(new Case(
Id = fc.ParentId,
Status = 'Open'
));
}
}
if(updates != null && updates.size() > 0)
update updates;
}
Many Thanks In Advance
I have pulled the below from another post (which works), but need to adopt it for the following circumstances, and wondered whether someone might be able to help please:
- For any update made, update field 'Last_Chatter_Feed_Timestamp__c' with todays date.
- For any update made and the profile ID = ABC, flip the status to 'Open'
trigger FeedThis on FeedComment(after insert, after update){
List<Case> updates = new List<case>();
List<id> userList = new List<ID>();
List<Id> feedItemList = new List<id>();
for(FeedComment fc: trigger.new){
feedItemList.add(fc.FeedItemId);
userList.add(fc.InsertedById);
}
Map<Id, FeedItem> feedMap = new Map<id, FeedItem>([select id,InsertedById,Visibility from feedItem where Id IN :feedItemList]);
Map<Id, User> userMap = new Map<Id, User>([select id, usertype, name from user where ID IN :userList]);
for(FeedComment fc: trigger.new){
if (feedMap != null && feedMap.containsKey(fc.feedItemId) && fc.ParentId.getSObjectType() == Case.SObjectType) {
updates.add(new Case(
Id = fc.ParentId,
Status = 'Open'
));
}
}
if(updates != null && updates.size() > 0)
update updates;
}
Many Thanks In Advance
replace the below code with the below new version hope it helps ..!!
updates.add(new Case(
Id = fc.ParentId,
Status = 'Open'
));
*********************new version************
case cs = new case();
cs.id = fc.ParentId;
cs.Last_Chatter_Feed_Timestamp__c = date.today();
if(UserInfo.getProfileId == 'ABC')
{
cs.Status = 'Open';
}
updates.add(cs);
Line 17 is :
- if(UserInfo.getProfileId == '00e3L000000M0wu')
Do I need to add something further up in the code too please?"Your organization's code coverage is 73%. You need at least 75% coverage to complete this deployment. Also, the following triggers have 0% code coverage. Each trigger must have at least 1% code coverage."