You need to sign in to do that
Don't have an account?
Ross 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);
}
}
}
Try using System.Trigger rather than just Trigger. I.e. if(System.Trigger.IsUpdate) ... for(SchedInt__c s : System.Trigger.new)... etc.
Andrew, I made the changes, but it only changed the error to:
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.
Thanks for the ideas, although I am still having the same problem.
I have updated my code with the 'same name' error fixed.
Still having trouble? I would create a new trigger, save it without any logic, then paste your code in.
syntactically it looks correct.
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!
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.
trigger LearningTrigger on Account (before insert) {
for(Account a : Trigger.New) {
a.Description = 'New description';
}
}
am getting unexpected token 'trigger'.
any solution Pls.