• Austin Callaro 8
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
Hello,

I continue to recieve a Compile Error when using the APEX Trigger functionalitly.  Below is the error message along with the source code I am using.  Please advise what I am missing here.

Error: Compile Error: Didn't understand relationship 'Line_Items__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 4 column 31

trigger DeleteRestrictInvoice on Invoice__c (before delete) {

  // create a list of Invoices in Trigger.oldMap along with their Line Items
  List<Invoice__c> invoices = [Select i.Name, (Select Name From Line_Items__r)
                                 From Invoice__c i
                                Where i.Id IN :Trigger.oldMap.keySet()];

  // loop through the Invoices, attaching errors to those that have Line Items
  for (Invoice__c invoice : invoices) {
    if (!invoice.Line_Items__r.isEmpty()) {
      Trigger.oldMap.get(invoice.id).addError('Cannot delete Invoice with Line Items');
    }
  }
}
 
Hello,

I continue to recieve a Compile Error when using the APEX Trigger functionalitly.  Below is the error message along with the source code I am using.  Please advise what I am missing here.

Error: Compile Error: Didn't understand relationship 'Line_Items__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 4 column 31

trigger DeleteRestrictInvoice on Invoice__c (before delete) {

  // create a list of Invoices in Trigger.oldMap along with their Line Items
  List<Invoice__c> invoices = [Select i.Name, (Select Name From Line_Items__r)
                                 From Invoice__c i
                                Where i.Id IN :Trigger.oldMap.keySet()];

  // loop through the Invoices, attaching errors to those that have Line Items
  for (Invoice__c invoice : invoices) {
    if (!invoice.Line_Items__r.isEmpty()) {
      Trigger.oldMap.get(invoice.id).addError('Cannot delete Invoice with Line Items');
    }
  }
}