You need to sign in to do that
Don't have an account?
Vida Yirenkyi
Help fix this code
Hello Experts,
I need help with this code to show only the words in the parent case description in the child case. At the moment the child case description lists all the keywords.
I need help with this code to show only the words in the parent case description in the child case. At the moment the child case description lists all the keywords.
trigger CheckSecretInfo on Case (after insert, before update) { String childCaseSubject = 'Warning: Parent case may contain secret info'; // Step 1: Create a collection containing each of our secret keywords Set<String> secretKeywords = new Set<String>(); secretKeywords.add('Credit Card'); secretKeywords.add('Social Security'); secretKeywords.add('SSN'); secretKeywords.add('Passport'); secretKeywords.add('Bodyweight'); List<Case> casesWithSecretInfo = new List<Case>(); Set<String> KeyWords = new Set<String>(); for (Case myCase : Trigger.new){ if(myCase.Subject != childCaseSubject){ // Step 2 Loop through secretkeywords and add all offending words to a Set for(String KeyWord: secretKeywords){ if(myCase.Description != null && myCase.Description.containsIgnoreCase(KeyWord)){ secretKeywords.add(KeyWord); break; system.debug('Keywords are: ' + keyword); } } system.debug('cases to create' + casesWithSecretInfo.size()); //Loop through secretkeywords and if there is any secret keywords add case to be created List<Case> casesToCreate = new List<Case>(); for(Case caseWithSecretInfo : casesWithSecretInfo){ Case childCase = new Case(); childCase.Subject = 'Warning: Parent case may contain secret info'; childCase.ParentId = caseWithSecretInfo.Id; childCase.IsEscalated = true; childCase.Priority = 'High'; childCase.Description = 'The following secret keywords were found: ' + KeyWords; casesToCreate.add(childCase); } insert casesToCreate; } } }Thanks
All Answers
To begin with, your List variable "casesWithSecretInfo" will not hold any value as this is not effectively used. Infact, its never used.
2nd, the break statement will exit the For Loop.
I have tried to re-write a part of the code w/ Comments to help you.
Hi Austin Mueller,
Thank you for your kind response to my quetion, It is much appreciated. I will give it a try.. Could you kindly give me detailed comments or explanations of your code please.
best regards
Vida