I have a custom object with the name RepairLines RepairLines have a master-detail relation to Case I use the standard Case system where i have a custom text field named Repair

In a Case trigger i have to write APEX code so each time the case is updated the repair field in the case must be updated with text fields from the related list RepairLines.

This text field is a summary of all repairs on the Case

I appreciate any help :-)

  • What do you mean exactly by "summarize text fields"? – martin Jun 26 '15 at 12:12
  • The case can have many hardware items each with a serial number. This serial number and the Repair action from a technician is saved in Object RepairLines. If there a repair lines on a case i want to get all the serial number and the actions and make a "case summary" in a text area on the Case. This case summary will be part of an email template. – Mads Siggaard Jun 26 '15 at 12:18

Hi try wirting a trigger on case in following format.

Replace "CaseText__c" & "ChildText__c" with your case & repair line text fields respectively and "RepairLines" with child relationship name.

trigger CaseTrigger on Case (after update){

    //List<Id> caseIdList = new List<Id>();

    //for(Case c : Trigger.new){
    //  caseIdList.add(c.Id);

    List<Case> caseListwithChild = [Select id,CaseText__c, (Select Id,ChildText__c from RepairLines) from Case where Id IN :trigger.new];

    for(Case c : caseListwithChild){
        for(RepairLines__c RL : c.RepairLines){
            c.CaseText__c = CaseText__c + RL.ChilcText__c + '\n';

        update caseListwithChild;
    catch(Exception e){}

Eric Note - commented out parts of the code that were not needed after a small modification

Hope this may help.

  • It would be best to put the trigger on the Children to update the parent when they are modified / added but this does provide a direct answer to the OP requirements – Eric Jun 26 '15 at 14:13
  • Eric and Nebula Thx a lot for your help. Now i have a trigger i can use. – Mads Siggaard Jun 26 '15 at 15:17
  • Actially the text from the repair lines are predefined text string that are translated to many languages. The cases are share between several contries and therefore the trigger can't sit on the child but have to fire when ever someone change the case. (the correct translation is then excuted and the case is updated) – Mads Siggaard Jun 26 '15 at 15:24

Here is my trigger based on nebulas answer

trigger SumtestTrigger on Case (before update) { try{ List caseIdList = new List();

for(Case c : Trigger.new)


List<Case> caseListwithChild = [Select id,ServiceResume__c, (Select Id 
from Repair_Line__r) from Case where Id IN :caseIdList];

for(Case c : caseListwithChild)
    System.debug('step 3');
    for(Repair_Line__c r : c.Repair_Line__r)
        System.debug('step 4');
        //do my stuff
catch(Exception e){}


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.