function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
JaimieLivesJaimieLives 

Apex Trigger -- compile error - variable does not exist?

OK. I'm tired, but can someone tell me why I keep getting "Error: Compile Error: Variable does not exist: c at line 42 column 16", when "c: is defined just a few lines above? Here's the relevant code...

 

trigger createCaseFromProject on SFDC_Project__c (after insert) {
    
    // iterate over the list of Project records being processed in the trigger and
    // create the required cases
    for (SFDC_Project__c prj : Trigger.new)

        //Define the Cases to Insert, then insert them

        // 01230000001B8slAAC   Account & Billing
        Case c = new Case(
            RecordType = '01230000001B8slAAC',
            Project__c = prj.Id,
            Subject = prj.Account__r.Name & ': Subject ',
            Description = ' Description ',
            Origin = 'From Project',
            SuppliedEmail = prj.Customer_Contact__r.Email,
            Contact = prj.Customer_Contact__r.Id,
            Account = prj.Account__r.Id,
            Status = 'New'
        );
        insert c;

}

 

The error is apparently in the line "insert c;"

But the variable is defined at the line "Case c = ..."

 

Or have my tired eyes missed something silly?

 

Thanks,

 

JaimieLivest

Best Answer chosen by Admin (Salesforce Developers) 
tukmoltukmol

you missed to enclose the codes in for loop with curly braces {}

All Answers

tukmoltukmol

you missed to enclose the codes in for loop with curly braces {}

This was selected as the best answer
JaimieLivesJaimieLives

Doh! Thanks!

 

Jaimie