Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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){
        parentIds.add(pa.Id);
    }

    // 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]){
        parentWithChildIds.add(Ch.EC_Invoice_num__r.Id);
    }
    // end of block

    for(ECInvoice__c pa : Trigger.Old){
        if(parentWithChildIds.contains(pa.Id)){
            pa.adderror('This guy has Children, You cannot hurt him!');
        }
    }
}
share|improve this question
    
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 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 at 17:47

Replace = with :.

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

See Loops.

share|improve this answer

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.');
    }        
}
share|improve this answer
    
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 at 17:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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