4

Attempting to deploy the trigger from this answer, on another question of mine. This is the second time I've attempted to deploy some apex, but this time I really would like to get it working. After repeatedly be puzzled to by where and what I need to do, it appears that that the version of Salesforce I'm using makes a difference; using EE, Enterprise Edition.

Reason I say that is because I got an error by going to "Setup > Build > Develop > Apex Triggers > Developer Console" then clicking "File > New > Apex Trigger" entering a "Name" and selecting the sObject as "Account" then clicked save. This resulted in an error saying, "ENTITY_IS_LOCKED: cannot create apex trigger on an active organization."

After a few Googles, it appears that to deploy the code above, I must follow these steps:

The Apex classes and triggers should first be written in a Developer Edition, Sandbox, or Trial organization along with the appropriate test methods that test at least 1% of triggers and 75% of classes. To deploy Apex into a production organization, a user with the Author Apex permission must deploy the triggers and classes using either the compileAndTest() or deploy() Metadata API methods which can be accessed with either the Apex Development Tool based on Apache ANT or the Force.com IDE based on Eclipse.]3

Issue is that that "makes sense" - but is way, way to high-level to be of any use, and the only other docs I've seen that "seem" complete are these: Writing Your First Apex Class and Trigger

Does it seem like those docs as a rough guide to deploying the trigger provided in the answer to my other question would be the fastest way to get this done?

If it matters, I do have access to both Developer & Developer Pro sandboxes, and have gotten the Force IDE loaded before, but just to do a download of the code as a semi-backup of the meta-data.

2 Answers 2

7

You need to write the code in a Sandbox (type doesn't matter) that is created from the Production org you want to deploy to. If it's a simple trigger & test class that you're mostly copying and pasting, then the Dev Console is fine, and you needn't worry about the IDE right at the moment.

The easiest deploy method is Change Sets, which lets you select components in your Sandbox and deploy them to your Production org (or another Sandbox). Deploying to Production will run your trigger's test, and any others in your org, and if you meet the code coverage requirements, you should be in business.

1
12

Note: The following was only tested on the Enterprise Edition using a Developer Pro type sandbox. Also, the reference to Contacts is based on me deploying a contact-trigger to the contact object, but at the very least the following should work for any standard object, and possibly any custom object.

  1. Create Sandbox (Deploy > Sandboxes)
  2. Confirm (Deploy > Deployment Connections)
  3. Click (Edit) for the sandbox just created
  4. Select “Allow Inbound Changes”, and click save
  5. Login to Sandbox (Deploy > Sandboxes : Select Correct Sandbox : Action > Login; use exist admin-user.sandboxname + existing password)
  6. Go to (Setup > Build > Customize > Contacts > Triggers > New)
  7. Paste code trigger code in, click save
  8. Click (Show Dependencies) to confirm trigger wired correctly
  9. Go to (Setup > Deploy > Outbound Change Sets) and click (New)
  10. Under “Change Set Components” click (Add)
  11. Under “Component Type:” select (Trigger) and let screen refresh
  12. Select the trigger just created, and click (Add to Change Set)
  13. Click (Upload) and confirm upload is final
  14. Wait for screen refresh to say “Your change set was uploaded successfully.”
  15. Return to production org
  16. Go to (Setup > Deploy > Inbound Change Sets)
  17. Select change set just sent
  18. Refresh screen using browser, confirm under “Deployment History” action status says “Succeeded”
  19. Click (Deploy)
  20. Refresh screen using browser, confirm under “Deployment History” action status says “Succeeded”
  21. Confirm Trigger deployed, go to (Setup > Build > Customize > Contacts > Triggers), find trigger deployed
2
  • Thank you so much! This was the best answer ever written lol so straight forward! Commented Feb 28, 2019 at 16:35
  • This is great and extremely helpful. Would you mind sharing your unit test for this trigger?
    – FWSFDC
    Commented Jan 10, 2020 at 16:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .