+ Start a Discussion
Dman100Dman100 

creating and deploying triggers

I read that you can only create a trigger in the sandbox.  Is this correct?  If so, how do you deploy the trigger to the production instance once the trigger has been created?  Does it automatically get added to the production environment or do you have to do something to deploy the trigger?
 
Are triggers available with the Professional Edition or only with the Enterprise and Unlimited Editions?
 
Thanks for any help.
jyotijyoti
Are you using any IDE to develop such as Eclipse?  If so, right-click on the source environment > Deploy to Server and walk through the steps to login to the target environment and select the artifacts to promote.  You can also do something similar with Ant although I don't have too much experience with that.
Dman100Dman100
No, I'm not using Eclipse to develop.  I use Visual Studio as my IDE to create custom applications that interface with the SalesForce API.
 
However, for the trigger, I had logged into our Sandbox instance and went to setup >> Customize >> Create >> Objects and selected the custom object I want to build a trigger for and selected new trigger.
 
I was going to build the trigger within the SalesForce sandbox environment?  Is this not the way to create the trigger?  Can I create a trigger within Visual Studio?  Do I have to use Eclipse?
 
I've never created a trigger before, so I'm shooting in the dark.
jyotijyoti
I cannot comment too much on Visual Studio, but if you are using the GUI to create/save triggers, consider using the Ant tool to deploy.  You will still need to save a local copy of the trigger (same way that Eclipse would).  But I would still recommend using Eclipse to develop triggers/classes as it is helpful in debugging rather than using the GUI.
wintamutewintamute
Hi,

Triggers and Apex code in general can only be created in either development orgs or sandboxes. Once everything is working there you can deploy it to production orgs. The easiest way to create the code and deploy it is to use Eclipse with the Force.com plugin since deployment is not possible via the browser and using ant is way harder than using Eclipse.
Keep in mind that to be able to deploy to production orgs you have to have unit tests that cover at 75% of your code.
One the triggers and everything else is working in salesforce as needed you can do your other development in Visual Studio using the newly exposed webservice methods (if you created some of course) via the wsdl file.

All development concerning salesforce objects and logic cannot be done in Visual Studio though.

regards,
Andreas
Dman100Dman100

Hi Andreas,

I just installed Eclipse, but I've never used before.  Are there any tutorials, simple examples to help get someone new to using Eclipse up and running.  As a starting point, I'm just want to create a couple of simple triggers that will auto populate some fields.  Once I'm successful at implementing those, I'd like to move into some more complex triggers.

Any tutorials that walk thru this process?  Not having used Eclipse before I feel very much in the dark as to where to start.

Also, can you explain what you meant about 75% unit testing to deploy to production?  I didn't understand what you meant.

Thanks for your help.

Regards.

jyotijyoti

I haven't seen any tutorials but the interface is very GUI-esque.  Make sure you have installed for Force.com plug-ins (from the mirror sites). 

First, catalog the instance you want by File > New > Force.com Project and walk through the steps to create the instance.  Common errors here are not specifying the correct endpoint or security token.

Then under the instance name, e.g. Sandbox, expand the tree to show src > unpackaged > triggers.  Right-click under the Force.com sub-menu click New Trigger.

SFDC has implemented some controls to make sure triggers do not run in infinite loops or use too many resources.  In order to test that your code is in "compliance", for lack of a better term, it requires a test class for each trigger and class.  There are some examples in the Cookbook that can help you to write triggers as well as their associated test classes.