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
Pranav ChitransPranav Chitrans 

Trigger syntax error unexpected

Can anyone plz tell what is the error.. I totaaly got pissed now... it shows error
Error: Compile Error: unexpected token: '{' at line 11 column 4
trigger feesCheck on Test__c (before insert, before update) 
{
  for(Test__c f : trigger.new)
  {
    if(trigger.isInsert && f.Fees__c < 1000)
    {
     f.addError('incorrect data 1000');
    }
    
 else(trigger.isUpdate && f.Fees__<1500 )
    {
      
     f.addError('greater than 1500');
    
     }
  
  }
  
}

 
Best Answer chosen by Pranav Chitrans
Abhishek BansalAbhishek Bansal
Hi,

Just a little mistake but please take care of this thing in future that you cannot add a condition in else statement.
Please correct your code as follows :
 
trigger feesCheck on Test__c (before insert, before update) 
{
  for(Test__c f : trigger.new)
  {
    if(trigger.isInsert && f.Fees__c < 1000)
    {
     f.addError('incorrect data 1000');
    }
    
 else if(trigger.isUpdate && f.Fees__<1500 )
    {
      
     f.addError('greater than 1500');
    
     }
  
  }
  
}

I have done modification at line no. 10.

Regards,
Abhishek