0

Error: Compile Error: unexpected token: 'List' at line 6 column 1

trigger AbortInsert on Adder__c (before insert)
{


System.debug('****************************************');
 List& amp;lt;Adder__c> adders = Trigger.new;



    for (Adder__c adder: adders)
    {
        if(AdderExt.fakeSave == true)
        {
            // AdderExt controls an editor that should only work on one row at a time
            System.assertEquals(adders.size(), 1);

            // Provide the evaluation results to the line item controller
            AdderExt.evaluationResults = adder;

            System.debug('adder='+adder);

            // Abort the save
            adder.addError('Throwing error to prevent DML for this formula only evaluation');
        }
    }
}

1 Answer 1

0

I'm not sure why you're using a List to put Trigger.new in, this seems like a waste of memory to me. Also, this line seems incorrect in general (did you try changing it to a HTML-friendly equivalent?):

List& amp;lt;Adder__c> adders = Trigger.new;

Please replace your code with:

trigger AbortInsert on Adder__c (before insert) 
{

    System.debug('****************************************');

    for (Adder__c adder: Trigger.new)
    {
        if(AdderExt.fakeSave == true)
        {
            // AdderExt controls an editor that should only work on one row at a time
            System.assertEquals(Trigger.new.size(), 1);

            // Provide the evaluation results to the line item controller
            AdderExt.evaluationResults = adder;

            System.debug('adder='+adder);

            // Abort the save
            adder.addError('Throwing error to prevent DML for this formula only evaluation');
        }
    }
}

As you can see we now use Trigger.new.size() directly in the for loop. Inside the for-loop we use Trigger.size instead of adders.size().

3
  • Compile Error: Variable does not exist: Trigger at line 15 column 33
    – user5633
    Commented Jan 21, 2015 at 9:09
  • I am getting error for your code
    – user5633
    Commented Jan 21, 2015 at 9:10
  • I've updated my code. If it still doesn't work, please paste the line that gives the error in here if you've changed anything. It seems that line 15 doesn't use the Trigger-variable at all. Commented Jan 21, 2015 at 9:20

You must log in to answer this question.

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