• Z3ro
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 4
    Replies

Hi Guys,

 

i am currently on a trigger for a rollup summary.

I´ve 2 Objects

Invoice= Parent

Product= Child

 

This is the Code what i actually have

 

trigger ProductRollup on Product__c (after delete, after insert, after update) {
 
    Set<id> InvoiceIds = new Set<id>();
    List<Invoice__c> InvoicesToUpdate = new List<Invoice__c>();
 
    for (Product__c item : Trigger.new)
        InvoiceIds.add(item.Invoice__c);
 
    if (Trigger.isUpdate || Trigger.isDelete) {
        for (Product__c item : Trigger.old)
            InvoiceIds.add(item.Invoice__c);
    }

    Map<id,Invoice__c> InvoiceMap = new Map<id,Invoice__c>([select id, test__c from Invoice__c where id IN :InvoiceIds]);

    for (Invoice__c Inv : [select Id, Name, test__c,(select id from Product__r) from Invoice__c where Id IN :InvoiceIds]) {
        InvoiceMap.get(Inv.Id).test__c = Inv.Product__r.size();
        InvoicesToUpdate.add(InvoiceMap.get(Inv.Id));
    }
 
    update InvoicesToUpdate;
 
}

 

i have an error in line 18 with (select id from Product__r)

Didn't understand relationship 'Product__r' in FROM part of query call

 

I just copied the trigger and adjusted it to my objects.

Can anyone help me with that code?

I am fairly new to apex and any help is appreciated.

 

BR

Tarek

  • June 24, 2013
  • Like
  • 0

Hi Guys,

 

i am currently on a trigger for a rollup summary.

I´ve 2 Objects

Invoice= Parent

Product= Child

 

This is the Code what i actually have

 

trigger ProductRollup on Product__c (after delete, after insert, after update) {
 
    Set<id> InvoiceIds = new Set<id>();
    List<Invoice__c> InvoicesToUpdate = new List<Invoice__c>();
 
    for (Product__c item : Trigger.new)
        InvoiceIds.add(item.Invoice__c);
 
    if (Trigger.isUpdate || Trigger.isDelete) {
        for (Product__c item : Trigger.old)
            InvoiceIds.add(item.Invoice__c);
    }

    Map<id,Invoice__c> InvoiceMap = new Map<id,Invoice__c>([select id, test__c from Invoice__c where id IN :InvoiceIds]);

    for (Invoice__c Inv : [select Id, Name, test__c,(select id from Product__r) from Invoice__c where Id IN :InvoiceIds]) {
        InvoiceMap.get(Inv.Id).test__c = Inv.Product__r.size();
        InvoicesToUpdate.add(InvoiceMap.get(Inv.Id));
    }
 
    update InvoicesToUpdate;
 
}

 

i have an error in line 18 with (select id from Product__r)

Didn't understand relationship 'Product__r' in FROM part of query call

 

I just copied the trigger and adjusted it to my objects.

Can anyone help me with that code?

I am fairly new to apex and any help is appreciated.

 

BR

Tarek

  • June 24, 2013
  • Like
  • 0