You need to sign in to do that
Don't have an account?
Mark Z Dean
Adding List of Strings to List of Object
I am trying to write a trigger on Case object that will detect specific confidential terms in the Description field and create a new CHILD case with the the detected terms in the Description field of the child record. I wrote the code below but having difficulty figuring out how to get the description of the new child record updated (line 34) with the confidential terms from the parent record.
trigger ConfidentialTerms on Case (after insert, before insert) { //insert all terms in list List<String> terms; Set<Case> NewChildCase = new Set<Case>(); List<Case> NewCases; String t; List<String> LString = new List<String>(); terms.add('Credit Card'); terms.add('Passport'); terms.add('License'); //iterate through terms list and check each record's description for(Case c : trigger.new){ for(String s : terms){ if(c.description.Contains(s) && c.Description != null){ t =+ s; NewChildCase.add(c); } } LString.add(t); } //create child record for(Case cc : NewChildCase){ Case childCase = new Case(); childCase.parentid = cc.id; childCase.Subject = 'High Priority Case'; childCase.Description = ''; NewCases.add(childCase); } insert NewCases; }I don't need the code but just hints on how this can be done. Much appreciated...
Class to stop recursion.
Trigger
@Raj - your code worked perfectly fine with some adjustments but how does the system know to fetch the description field from the record in line below? I could have had another text field as well in NewChildCase so how would I differentiate which one I want to use for description:
@Steve - I corrected the code to run only once to avoid recursion but how would it run if there were buld records? or is each record that needs processing run into its own execution context? Because if not, once the firstRun is set to false, it wouldn't run for the next record.