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
advlgxadvlgx 

Step by Step.... What do I do to upload a trigger through Eclipse?

Is there a plain english version of how to get your trigger published into a prod org? I am new at doing this and would be interested in a step by step guide to what I am supposed to do. I am getting "code coverage" and "testing" errors when trying to upload the new trigger. What do I have to do to get force.com to accept my deployment of a simple trigger. My code is quite basic, automatically setting the contact owner to the associated account owner:

trigger ContactAcct on Contact (after insert, after update)

{

  for (Contact c : trigger.new)

   { 

      Set<Id> aid = new Set<Id>();

      aid.add(c.AccountId);

      Account accid = [SELECT OwnerId, Name FROM Account where id in :aid];

      if(accid.OwnerId <> c.OwnerId)

      {

          Set<Id> cid = new Set<Id>();

          cid.add(c.Id);

          Contact con = [select OwnerId,Account.Name from Contact where id in :cid];

          con.OwnerId = accid.OwnerId;

          update con;

      }

   }

}


RickyGRickyG
I would suggest you read the relevant chapters in the Developer Guide, especially Chapter 10, which introduces Apex and test coverage.  The book also covers the IDE and various deployment options.

You can get the book as part of the Force.com library.  Hope this helps.
advlgxadvlgx
Ok..... hello world works great of course :smileywink:

So, now how would one, for example, use Execute Anonymous to test the code in a trigger? I find no mention of this process or I missed it. I tried inserting my trigger code in various ways within the system.debug call without success. Do I have to create a whole class and implement my trigger code in the class, then test the class? How would doing that carry over to the system understanding that I tested my trigger, the next time I uploaded it. If I'm missing something, please point out to me, but I do not see any correlation in the developer guide between writing classes and testing them, vs. the code I write and deploy as a trigger.