+ Start a Discussion
Keer YenduriKeer Yenduri 

trigger error

trigger Comparision on Account(before update)
{
    for(Account acc : Trigger.new)
    {
    Account oldAccount = Trigger.oldMap.get(acc.ID)
        if(acc.AccountNumber!=oldAccount.AccountNumber)
        {
        System.debug('Account number is changed');
        System.debug('old account');
        System.debug('new account');
        acc.Type = 'prospect';
        }
        else
        {
        System.debug('number has not been changed');
        acc.Type = 'other';
        }

    }
}

in this program i got this error like:
Compile Error: unexpected token: 'trigger' at line 1 column 0



 
Best Answer chosen by Keer Yenduri
lakslaks

Hi,

Are you trying to create a trigger by going to Apex classes section in your org by any chance ?

If so, please go to Setup -> Build -> Develop -> Apex Triggers and try creating.

Regards,
Lakshmi.

All Answers

Swagato RaySwagato Ray
Hi Keer,

Your trigger is fine but try this 
 
trigger Comparision on Account(before update)
{
    for(Account acc : Trigger.new)
    {
    Account oldAccount = Trigger.oldMap.get(acc.ID);
        if(acc.AccountNumber!=oldAccount.AccountNumber)
        {
        System.debug('Account number is changed');
        System.debug('old account');
        System.debug('new account');
        acc.Type = 'prospect';
        }
        else
        {
        System.debug('number has not been changed');
        acc.Type = 'other';
        }

    }
}

 
Keer YenduriKeer Yenduri
Hi,
again i got the same error
lakslaks

Hi,

Are you trying to create a trigger by going to Apex classes section in your org by any chance ?

If so, please go to Setup -> Build -> Develop -> Apex Triggers and try creating.

Regards,
Lakshmi.
This was selected as the best answer
Keer YenduriKeer Yenduri
Hi Laks,

solved my problem.

Thanks
Keer YenduriKeer Yenduri
Hi,

"please go to Setup -> Build -> Develop -> Apex Triggers and try creating."

this is the best answer
Keer YenduriKeer Yenduri
Hi Laks,

but how can i find whether the trigger is fired or not.
please let me know.
lakslaks
Hi,

To know whether the trigger has been fired or not, you can check if your debug statements are logged in the Debug log.
Check under -> Setup -> Monitor -> Logs -> Debug logs

Regards,
Lakshmi.
Keer YenduriKeer Yenduri
Hi Laks,

Thanks,
Keer