You need to sign in to do that
Don't have an account?
Justin Lonis
One line in this trigger is causing a problem for us
Hi thanks to SF Issue-Fixer, we got this awesome trigger but for some reason we can't get it to completely fire correctly.
The trigger was to have a status change on a feed comment so here is the first one:
This trigger allows anyone's feed comment to change the status
01trigger CommentStatusUpd on FeedComment (after insert) {
02
03 for (FeedComment feedcs : trigger.new){
04
05 List<CaseFeed> chkCsFeed = [ SELECT Id FROM CaseFeed WHERE ParentId=: feedcs.ParentId ];
06 if( chkCsFeed.size() > 0){
07 system.debug('***DEBUG***'+feedcs.ParentId);
08 List<Case> Pros = new List<Case>([ SELECT CaseNumber, Id, Status FROM Case WHERE Id =: feedcs.ParentId ]);
09 for (integer i = 0; i < Pros.size(); i++){
10 system.debug('***DEBUG-INFO: CaseId***'+Pros[i].Id);
11 system.debug('***DEBUG-INFO: CaseNumber***'+Pros[i].CaseNumber);
12 system.debug('***DEBUG-INFO: CaseStatus***'+Pros[i].Status);
13 Pros[i].Status = 'Working';
14 }
15 update Pros;
16
17 }
18
19 }
20
21}
However, we only wanted the status to change if a specific profile (00e800000018sx8) so only their feed comment on a case would change the status from "Awaiting Customer Feedback" to "Working":
This trigger is supposed to only have the status change when 00e800000018sx8 profile makes a feed comment.
trigger UpdateCommStatus on FeedComment (before 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;
}
}
}
There are some differents between the two triggers which both are supposed to change the status. Can anyone help with figuring out why it is not firing for the profile?
Thanks,
The trigger was to have a status change on a feed comment so here is the first one:
This trigger allows anyone's feed comment to change the status
01trigger CommentStatusUpd on FeedComment (after insert) {
02
03 for (FeedComment feedcs : trigger.new){
04
05 List<CaseFeed> chkCsFeed = [ SELECT Id FROM CaseFeed WHERE ParentId=: feedcs.ParentId ];
06 if( chkCsFeed.size() > 0){
07 system.debug('***DEBUG***'+feedcs.ParentId);
08 List<Case> Pros = new List<Case>([ SELECT CaseNumber, Id, Status FROM Case WHERE Id =: feedcs.ParentId ]);
09 for (integer i = 0; i < Pros.size(); i++){
10 system.debug('***DEBUG-INFO: CaseId***'+Pros[i].Id);
11 system.debug('***DEBUG-INFO: CaseNumber***'+Pros[i].CaseNumber);
12 system.debug('***DEBUG-INFO: CaseStatus***'+Pros[i].Status);
13 Pros[i].Status = 'Working';
14 }
15 update Pros;
16
17 }
18
19 }
20
21}
However, we only wanted the status to change if a specific profile (00e800000018sx8) so only their feed comment on a case would change the status from "Awaiting Customer Feedback" to "Working":
This trigger is supposed to only have the status change when 00e800000018sx8 profile makes a feed comment.
trigger UpdateCommStatus on FeedComment (before 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;
}
}
}
There are some differents between the two triggers which both are supposed to change the status. Can anyone help with figuring out why it is not firing for the profile?
Thanks,
trigger UpdateCommStatus on FeedComment (before 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) {
Profile myProfile = [SELECT Id FROM Profile WHERE Name: = '00e800000018sx8'];
if ( user.profileId == myProfile.Id ) {
Pros[i].Status = 'Working';
}
}
}
update Pros;
}
}
}
Error : unexpected token: ':' line 10
Profile myProfile = [SELECT Id FROM Profile WHERE Name = 'Profile Name'];
https://developer.salesforce.com/page/Best_Practice%3A_Bulkify_Your_Code
You'll want to stick the query outside the for loop. Usually all trigger logic would actually be in a seperate apex class, and not within the trigger itself. But you can check that out yourself.
So your code should look like this:
got an error on line 14: Comparison arguments must be compatible types: Schema.SObjectField, Id
My apex knowledge is minimal at best so I appreciate all the help from everyone thus far. I feel we are close!
Thanks,
Try above code.
Hi Venky409,
Got this error when as a Customer under profile "00e800000018sx8." Also, in the trigger you provided where can I put the profiles that I want to be able to change the status so "00e800000018sx8." Like discussed above we don't want internal case owners to have comments that change this status.
in above Replace some profile with profile name you want to match like Marketing User or System Administrator or whatever name you want that exists in system
and Create a new customlabel called ProfileNames with value as Profile names separated by comma
How does this look? I was going to do the multiple profile trigger but wanted to keep it simple for now so I'll do the one profile one:
trigger UpdateCommStatus on FeedComment (before insert) {
Id myProfileId = [SELECT Id FROM Profile WHERE Name = 'CardinalCommerce Customer' limit 1].id;
set<Id> feedparentIds = new set<Id>();
for (FeedComment feedcs : trigger.new){
feedparentIds.add(feedcs.ParentId);
}
List<Case> Pros = new List<Case>();
Pros = [SELECT CaseNumber, Id, Status, owner.type,OwnerId,owner.ProfileId FROM Case WHERE Id =: feedparentIds ];
if(pros.size()>0){
for(Case cs : Pros){
if(cs.owner.type == 'User'){
if(cs.owner.ProfileId == myProfileId){
cs.Status = 'Working';
}
}
}
update pros;
}
}
Do I need anything else? I'm doing this in sandbox, saved the trigger and went to a ticket and it still didn't change the status. Just wanted to confirm that I didn't miss anything like the last time. Also just to confirm, I don't need anywhere in this code that it was in awaiting customer feedback first, right?
Also, I saw your note
and Create a new customlabel called ProfileNames with value as Profile names separated by comma. I need to learn how to create a customlabel as I am just getting started with Apex. So that's why I stuck with the first one-profile trigger.
Thanks,
Added awaiting customer check as well. Check whether profile name is correct or not? Code looks good.
I'm not sure if this helps but the user's are CSPLitePortal. But we don't have any special permissions. The status field is also required on all page layouts for field accessibility.
Just for theory sake, with the very first trigger I posted to where it has evolved to...why did we get rid of the <case feed> since that is what the customers are commenting on? A feed comment on the case feed.
List<CaseFeed> chkCsFeed = [ SELECT Id FROM CaseFeed WHERE ParentId=: feedcs.ParentId ];
List<Case> Pros = new List<Case>([ SELECT CaseNumber, Id, Status, OwnerId FROM Case WHERE Id =: feedcs.ParentId
I put this towards the beginning: system.debug('***debugtest***');
How can we tell if it is firing?
*This is all I have to share from a log perspective
LOGS: 10:19:47:016 SOQL_EXECUTE_BEGIN [46]|Aggregations:0|select id, LastModifiedDate, lead_grade__c, first_conversion_date__c, first_conversion_event__c, recent_conversion_date__c, recent_conversion_event__c, guid__c, found_site_via__c, hubspot_detail__c, ip_address__c, conversion_events__c, website_visits__c, total_page_views__c, first_visit__c, recent_visit__c, lead__c, contact__c, ip_region__c, ip_city__c, ip_country__c, portal_id__c from HubSpot_Intelligence__c where Contact__c ='003540000026FEO'
10:19:47:042 SOQL_EXECUTE_END [51]|Rows:0
10:19:47:053 CUMULATIVE_LIMIT_USAGE
10:19:47:036 SOQL_EXECUTE_END [46]|Rows:0
I added the last line of code from yesterday that you gave (the last comment from 3/16) and got this problem(s): Variable does not exist: feedcs.ParentId line 17
trigger UpdateCommStatus on FeedComment (before insert) {
Id myProfileId = [SELECT Id FROM Profile WHERE Name = 'CardinalCommerce Customer' limit 1].id;
set<Id> feedparentIds = new set<Id>();
for (FeedComment feedcs : trigger.new){
feedparentIds.add(feedcs.ParentId);
}
List<Case> Pros = new List<Case>([ SELECT CaseNumber, Id, Status, OwnerId FROM Case WHERE Id =: feedcs.ParentId]);
if(pros.size()>0){
for(Case cs : Pros){
if(cs.owner.ProfileId == myProfileId && cs.Status == 'Awaiting Customer Feedback'){
cs.Status = 'Working';
}
}
}
update pros;
}
What I'm thinking is it's a scope error, right?
List<Case> Pros = new List<Case>([ SELECT CaseNumber, Id, Status, OwnerId FROM Case WHERE Id =: feedparentIds]);
Thanks again for you help. Here is the new code with a different error (argggg...lol). I bolded the error in the code and provided a screenshot. Can we take one more stab at this? If we need to get another set of eyes on this I can repost to another thread in the developer community and mark you as best answer for your hard work. I appreciate everyone taking the time to help out with this, it means the world to me!!!
trigger UpdateCommStatus on FeedComment (before insert) {
Id myProfileId = [SELECT Id FROM Profile WHERE Name = 'CardinalCommerce Customer' limit 1].id;
set<Id> feedparentIds = new set<Id>();
for (FeedComment feedcs : trigger.new){
feedparentIds.add(feedcs.ParentId);
}
List<Case> Pros = new List<Case>([ SELECT CaseNumber, Id, Status, OwnerId FROM Case WHERE Id =: feedparentIds]);
if(pros.size()>0){
for(Case cs : Pros){
if(cs.owner.ProfileId == myProfileId && cs.Status == 'Awaiting Customer Feedback'){
cs.Status = 'Working';
}
}
}
update Pros;
}
Try this one. we have to query that field in soql . i changed that
Just want to confirm I'm doing everything correct on my end....adding new changes to trigger in developer console...saving....refreshing customer ticket...submitting new feed comment (while ticket "status" is in "Awaiting Customer Feedback") and then evaluating if it works? I don't have a test class prepared (although in sandbox you don't need it, right?) and I have 82% coverage.
I might have some error messages....I'll put some screenshots below:
Hopefully we are getting close! Thanks!!
1. Check whether you are testing with right profile or not
2. Check the data.
Checked the profile.