You need to sign in to do that
Don't have an account?
furamag
Eclipse and error in trigger
I have a trigger. My trigger update one field in custom object. This is code of trigger:
I tested my trigger in development version of salesforce. It wirked correct. Now I want to install this trigger to real version of salesforce.
To check my trigger and transfer it to real version I use Eclipse. But I have two errors when I check my trigger:
Why I have this errors and why I can't save this trigger to server (trigger_name -> Force.com -> Save to Server).
Code:
trigger Update on Promotions__c (after insert, after update) { Promotions__c[] opp = trigger.new; String title = opp[0].Title__c; String id = opp[0].Employee__c; SFDC_Employee__c s = [SELECT Title__c FROM SFDC_Employee__c WHERE ID = :id]; s.Title__c = title; update s; }
I tested my trigger in development version of salesforce. It wirked correct. Now I want to install this trigger to real version of salesforce.
To check my trigger and transfer it to real version I use Eclipse. But I have two errors when I check my trigger:
Code:
cvc-complex-type.2.4.b: The content of element 'ApexTrigger' is not complete. One of '{"http://soap.sforce.com/2006/04/metadata":status}' is expected. Save error: unexpected token: Update
Why I have this errors and why I can't save this trigger to server (trigger_name -> Force.com -> Save to Server).
This will guide you through the process of connecting to your production organization, selecting the components to deploy, and pre-validating and/or executing the deployment.
(If you tried to deploy to another organization by creating another Force.com Project connected to that organization, and dragging-and-dropping a .trigger file to the new project, you should know that this is not a supported action. The IDE can't prevent you from dragging files from project to project within Eclipse, but this kind of drag-and-drop generally won't work--especially against a production org, where Apex code coverage requirements are enforced.)
Jon
Second file contain this code:
When I validate all my package I have many errors in Update.trigger-meta.xml:
When I try to Deploy to Server I have an error "unexpected token: Update".
Message Edited by furamag on 10-22-2008 09:25 AM
Message Edited by furamag on 10-22-2008 09:25 AM
My 'meta' trigger files all contain the following tag:
<status>Active</status>
Not sure why it would be missing from yours - but try adding it and see if your deploy suddenly works. (This is within the 'ApexTrigger' block)
...you will also have to 'cover' this trigger with a Testmethod, if your target org is a Production org...
Message Edited by philbo on 10-22-2008 02:57 PM
I already read about Testmethod, but I don't understand why I need to use Testmethod if I test my trigger in development accaunt. I tried to make Testmethod but I don't know what this method have to do and where I have to whrite this method.
Check the Apex language documentation for details (+ rationale) on how to write Testmethods for your code (can get it via the SF Help window).
Looking at your trigger...a few things to consider:
Where I have to write my test class? In eclipse or in my development accaunt?
My guess is that you're trying to use a reserved word 'update' as the name of your trigger. Why not try changing the trigger name - something like 'updateEmployees' or whatever - maybe this'll squash your problem.
Message Edited by JonP on 10-23-2008 09:06 AM
I don't know where is main part of trigger.
Where in Eclipse I have to write test class and how can I work with my trigger from test class.
I am already made 4 triggers, but I can't use it's in salesforce because I can't make test class.
My test class:
1. Save error: unexpected token: : line 8
2. List has no rows for assignment to SObject line 16
How can I fix this errors?
Let's start with the explicit compile errors in your test class:
1. As the error pretty clearly states, on line 8 the ":" character in ":id" does not belong, and should be removed. The SOQL query language uses ":<variable>" notation to let you inject Apex variables into your search queries. But line 8 is normal Apex code, not a SOQL query, so you don't need the ":".
2. On line 16 of your test class, you are assigning the result of a SOQL query to a singular variable. SOQL queries return Lists. The List may be empty, or only have one item in it, but it's still a List object. You have two options here: (1) Change the assignment variable to a List type, e.g.:
or (2) add the LIMIT keyword to your SOQL query to ensure it returns a maximum of one result, so you can assign it directly to your singular variable:
In this case, option 2 makes the most sense, because your search criteria is based on ID, so in reality you will only get 0 or 1 results.
Those changes will resolve your immediate issues, but there are a few other things you'll need to do before this trigger is ready to go live:
Implementing these changes should get you pretty close to what you need, I hope.
Unit testing definitely requires a shift in mindset, but it pays big dividend over time. An advanced technique that is part of the Extreme Programming (XP) discipline is called Test Driven Development, in which you write your tests before you write your code. This way, you work out the inputs and expected outputs before you write your code, so by the time you start writing the actual code you know more or less exactly what it needs to do. Plus you know you're done when all your tests pass!
Happy coding,
Jon
1. As the error pretty clearly states, on line 8 the ":" character in ":id" does not belong, and should be removed. The SOQL query language uses ":" notation to let you inject Apex variables into your search queries. But line 8 is normal Apex code, not a SOQL query, so you don't need the ":".
When I delete ":" in this string "Promotions__c opp = new Promotions__c(Name = 'test_trg', Employee__c = :id)" I have an error: "Save error: Variable does not exist: id".
As a general rule you should avoid using reserved words as variable names. If I were you I would change my 'id' variable to 'emplId' or something. This may be what's causing your syntax error.
"a0A70000002lsUj" - id one of employee.
And I have two errors:
1. Save error: Initial term of field expression must be a concrete SObject: LIST:SOBJECT:Promotions__c.
2. System.StringException: Invalid id: Success.
I tried to use "Promotions__c[] s = [SELECT Title__c FROM Promotions__c WHERE ID = :id];" and "Promotions__c s = [SELECT Title__c FROM Promotions__c WHERE ID = :id LIMIT 1];" but I have same errors.
Thanks,
Jon
salesforce.com Product Manager
In the latest Force.com IDE (Winter '09 / 14.0) we've added the ability to override the "No Action" decision and deploy anyway. If you haven't done so already, you may want to upgrade.
Note that there's no direct upgrade path from the Developer Preview releases (13.0 or older) of the IDE plug-in or projects. You'll need to uninstall the old plug-in and delete your old Force.com projects before installing 14.0, then recreate your projects. Or you can just install a second copy of Eclipse for the 14.0 plug-in and gradually transition over to it.