I'm getting the following error on the code below.

expecting a semi-colon, found ')'

I have placed comments around the offending block. I know it is the offending block because if I remove it, I have no more errors.

trigger HF_preventECInvoiceDelete on ECInvoice__c (before delete) {
    Set<Id> parentWithChildIds = new Set<Id>();
    Set<Id> parentIds = new Set<Id>();
    for(ECInvoice__c pa : Trigger.Old){

    // error is in this block
    for(Payment_received__c Ch = [select id, EC_Invoice_num__c, EC_Invoice_num__r.Id from Payment_received__c where ECInvoice__c =: parentIds]){
    // end of block

    for(ECInvoice__c pa : Trigger.Old){
            pa.adderror('This guy has Children, You cannot hurt him!');
  • Not sure how the site selected the code in my post, but there is code above and below the code that was put in the grey area by the site.
    – Hal9999
    Feb 17, 2016 at 17:43
  • You need a blank line between any text and the start of your code block. Also any line that starts with fewer than four spaces will break the parser.
    – Adrian Larson
    Feb 17, 2016 at 17:47

2 Answers 2


Replace = with :.

for(Payment_received__c record : [SELECT ... FROM Payment_received__c]

See Loops.


Thanks for the replies. I ended up doing this instead:

trigger HF_DeleteECInvoice on ECInvoice__c (before delete) {
    List<Payment_received__c> lis = [select EC_Invoice_num__c from Payment_received__c
        where EC_Invoice_num__c in :Trigger.oldMap.keyset()];

    for (Payment_received__c li : lis)
        trigger.oldmap.get(li.EC_Invoice_num__c).adderror('Invoice has payments applied! Cannot delete.');
  • That is essentially the same fix...you needed to use : instead of =. It is actually less efficient because you no longer get the benefits of for loop batching.
    – Adrian Larson
    Feb 18, 2016 at 17:05

You must log in to answer this question.

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