1

I have two objects. Child Object: Service_Item__c and Parent Object: Case, with master detail relationship. so when a record is inserted or updated I want to add Service_Id__c and Service_Description__c to the Parent custom field Service_Items__c with comma separated(field1__c,Field2__c).

I have copied and adjusted the code from how to add child record fields into a single field in Parent object using trigger?

However I am getting the following error message:

Error Error: Compile Error:

Service ID, Service Description from Service_Item__r) from Case where

^

ERROR at Row:1:Column:74

Didn't understand relationship 'Service_Item__r' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names. at line 12 column 24

Any help would be greatly appreciated :)

Trigger

trigger updateVals on Service_Item__c(after Insert, after Update) {

List < Case > poList = new List < Case > ();
Set < Id > Po_Ids = new Set < Id > ();

for (Service_Item__c childObj: Trigger.new) {
    Po_Ids.add(childObj.Case__c);
}


if (Trigger.IsInsert || Trigger.IsUpdate) {
    List < Case > po = [Select Id, Service_List__c, (Select Service ID, 
Service Description from Service_Item__r) from Case where Id IN: Po_Ids];
    for (Case p: po) {
        String concatenateString = '';
        for (Service_Item__c c: p.Service_Item__r) {
            concatenateString += c.Service_ID__c + ',' + c.Service_Description__c + ' : ';

        }
        p.Service_Items__c = concatenateString;
        poList.add(p);
    }


    update poList;

}

}
1
  • 2
    From refers to an object table and Service_Item__r is considered as a field. Other than that I don't understand why the SELECT is not crushing on "SELECT Service ID" as they should be separated by a comma or linked by an underscore Nov 27, 2018 at 11:56

1 Answer 1

1

Try to use the plural of the related object. From Service_Item__r to this Service_Items__r. I assume that the plural for Service Item is Service_Items__c :)

It looks like not quite right:

if (Trigger.IsInsert || Trigger.IsUpdate) {
    List < Case > po = [Select Id, Service_List__c, (Select Service ID, 
Service Description from Service_Item__r) from Case where Id IN: Po_Ids];

This part: Service Description what are those?

1
  • the Service Description and Service ID are two custom fields within the child object that I would like to add to concatenate. I have updated these to the API names and it has worked! Thanks for your help!
    – Jack
    Nov 27, 2018 at 12:47

Not the answer you're looking for? Browse other questions tagged .