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
Ross JamesRoss James 

Error: Compile Error: unexpected token: 'trigger' at line 1 column 0

Can someone tell me the obvious and silly mistake I am making?

 

trigger GoItemfromAsset on SchedInt__c (before update) { if(Trigger.isUpdate) { for(SchedInt__c s : Trigger.new) { if (s.ItemFromAsset__c==true) { ItemfromAsset.createItemfromAsset(); } } }}

 

 

 

The class is as follows: 

 

 

public with sharing class ItemfromAsset {
    
    public static Map<id, Asset> getAssetToCreateItem() {
        
        DateTime dT = System.now();
        String myDate = dT.format('d');
        Decimal myDay = decimal.valueOf(myDate);
        
        List<Asset> asts =  [select id, name, AccountId, Billing_Product__c, Quantity 
                                from asset 
                                where Day__c = :myDay
                                and Status = 'Active'];
        Map<id, Asset> result = new Map<id, Asset>();
        for (Asset ast : asts) {
            result.put(ast.id, ast);
        }
        return result;
    }
    

    public static void createItemsfromAsset() {
        
        DateTime dT = System.now();
        String myDate = dT.format('d');
        Decimal myDay = decimal.valueOf(myDate);
        
        Map<id, Asset> AssetIdToItem = getAssetToCreateItem();
        system.debug('got AssetIdToItem map of size ' + AssetIdToItem.size());
        
        Map<id, Asset> idToAsset = new Map<id,Asset>();
        
        List<Item__c> Items = new List<Item__c>(); 
        
        List<Asset> assets = [select id, name, AccountId, Billing_Product__c, Quantity 
                                from asset 
                                where Day__c = :myDay 
                                and Status = 'Installed'];
        System.debug('***** accounts returned = ' + assets.size());
        
        insert items;
        
        Map<id,id> astToItem = new Map<id, id>();
        System.debug('***** about to iterate throught the items');
        
        for (Item__c currItem : items) {
            astToItem.put(currItem.asset__c, currItem.id);
            System.debug('***** accid/invid = ' + currItem.account__c + '/' + currItem.id);
        }
        }
        }

 

 

 

Message Edited by Ross James on 03-01-2010 07:54 PM
Message Edited by Ross James on 03-01-2010 07:55 PM
uptime_andrewuptime_andrew

Try using System.Trigger rather than just Trigger.  I.e. if(System.Trigger.IsUpdate) ... for(SchedInt__c s : System.Trigger.new)... etc.

 

Ross JamesRoss James

Andrew, I made the changes, but it only changed the error to:

 

Error: Compile Error: unexpected token: 'system.trigger' at line 1 column 0

 

JimRaeJimRae
Maybe it needs to be Trigger and not trigger (case sensitive)?
cloudcodercloudcoder

Your triggers method signature is correct, but from the look of your code (it's hard to see though as the formatting is a little screwy) both your trigger and class is called ItemfromAsset.

 

Since you are calling the ItemfromAsset class from within your trigger (of the same name), you are going to have issues.

 

Try changing the class name to something unique. 

Ross JamesRoss James

Thanks for the ideas, although I am still having the same problem.

 

I have updated my code with the 'same name' error fixed. 

cloudcodercloudcoder

Still having trouble? I would create a new trigger, save it without any logic, then paste your code in.

 

syntactically it looks correct. 

SuperfellSuperfell
Perhaps you're trying to create a trigger in the apex classes tab, and not in the relevant triggers tab ? (i.e. you're writing trigger code where a class is expected)
Ross JamesRoss James

With thanks to everyone, I have updated Eclipse and gone back to doing ALL my dev work there - even the small stuff.

 

No issue compiling this trigger in Eclipse. Sorry to waste everyones time.

 

Thanks again! 

Joey HoJoey Ho

I did the same mistake of creating a trigger directly Your Name | Setup | Create | Apex Classes (this is not the right way)

The correct way to do this is to go to the standard/custom object itself and click on the Triggers and clicking the new button there.

Lakshmi Usha RamabhotlaLakshmi Usha Ramabhotla
Hi

trigger LearningTrigger on Account (before insert) {
    for(Account a : Trigger.New) {
    a.Description = 'New description';
    }   
}

am getting unexpected token 'trigger'.

any solution Pls.