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
myanceymyancey 

Help me deploy my first trigger

Stumbling thru examples, I have successfully written and tested my first trigger.   I did this in my Sandbox and now want to deploy it to production.  I've installed the Migration Tool , Ant and Java SDK and done the required configurations.    But, the instructions for using Ant to move move it are too confusing and use too many terms I'm not familiar with.  Plus the Migration Tool User Guide is 25 pages long.  It can't be that complex to move a 6 line trigger from Sandbox to production.   Please help!

Best Answer chosen by Admin (Salesforce Developers) 
sh-at-youseesh-at-yousee

As you know now the failing classes weren't in your package. However, everytime you deploy something to production all tests are run and an overall code coeverage of 75% is required (including your new code).

 

You need to update the classes in production so that your overall test coverage is above 75%. You won't be able to deploy anything until then.

 

The classes can be edited in two ways:

 

  1. Using Eclipse and the Force.com IDE
  2. Directly in the class in your Sandbox

Since you deleted the classes in your Sandbox you're looking at having to use Eclipse. I guess there's also a third way which would be to create the classes again in your Sandbox and then editing them there.

 

The errors you're seeing is because the test methods are trying to insert a record where the required field Committed_MRR__c hasn't been assigned a value.

 

I think if you get that fixed you'll be a step closer to deploying your own trigger.

 

/Søren Nødskov Hansen

All Answers

BA_AdminBA_Admin

It is easy to deploy using eclipse or you can use the UI to deploy, go to App setup-Deploy and make the connection from ur sandbox to production and just deploy the trigger, it is very easy to deploy this way, even yuou have help on the top right if you have any questions regarding this functionality, let me know if you have any questions

sh-at-youseesh-at-yousee

Hi,

 

As already suggested I'd use Eclipse with the Force.com plug-in. However, there is another way of doing this which requires no 3rd party software.

 

You could use the Change Set feature. You can find it here: Setup --> Deploy --> Outbound Change Sets.

 

Here you have the option to create an Outbound Change Set containing your trigger and test class (and a lot of other stuff, if needed). You simply need to establish a connection from your Sandbox to your Production and you're good to go.

 

Hope it helps.

 

/Søren Nødskov Hansen

myanceymyancey

Well, this is a lot easier, thanks.  

 

I've bumped into my next issue.   I ran my tests in my sandbox and got 100% coverage.  I built a outbound Change Set that contained only my trigger and uploaded it.  Then switched to my production org and deployed it.  But it failed saying there was only 23% coverage.  I don't understand why it was 100% in the sandbox and only 23% in production.

myanceymyancey

It's much easier.  Thanks

 

In my sandbox my tests show 100% coverage but my production deploy fails stating only 23% coverage.  Any ideas?

sh-at-youseesh-at-yousee

Hi,

 

Is your test method placed in the same file as your trigger or is it in a separate file?

 

If it is in a separate file you need to also add that to the Change Set.

 

/Søren Nødskov Hansen

myanceymyancey

I think I may be having the opposite problem.  When my deploy fails, it lists a bunch of other test classes that were written by others.   My trigger may have 100% coverage but these others don't.   I think I need to exclude them from the Change Set.  How would I do that?  Also, I don't even see my test class in the list.  Is that becuase it had no errors?  See next post

myanceymyancey

Failed ( 5 )

API Name
Type
Line
Column
Problem
ProductsToAssetsTester.testAIDQueryParamsMissing()Class584Failure Message: "System.Exception: Assertion Failed: Expected: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Committed MRR is required: [Committed_MRR__c], Actual: Manual Exception: OID or AID is Null!", Failure Stack Trace: "Class.ProductsToAssetsTester.testAIDQueryParamsMissing: line...
ProductsToAssetsTester.testExceptionBlocks()Class3674Failure Message: "System.Exception: Assertion Failed: Expected: Manual Exception: OID or AID is Null!, Actual: Manual Exception!", Failure Stack Trace: "Class.ProductsToAssetsTester.testExceptionBlocks: line 367, column 4 External entry point"
ProductsToAssetsTester.testInvalidAIDQueryParam()Class1244Failure Message: "System.Exception: Assertion Failed: Expected: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Committed MRR is required: [Committed_MRR__c], Actual: Invalid id: 001A123456789123", Failure Stack Trace: "Class.ProductsToAssetsTester.testInvalidAIDQueryParam: line 124, colu...
Test_OpportunityTrigger.test_OpptyInsert()Class363Failure Message: "System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Committed MRR is required: [Committed_MRR__c]", Failure Stack Trace: "Class.Test_OpportunityTrigger.test_OpptyInsert: line 36, column 3 External entry point"
Deploy Error   Average test coverage across all Apex Classes and Triggers is 24%, at least 75% test coverage is required
myanceymyancey

I deleted all of these test classes, except mine, from the sandbox.  It's just a copy of prod, right?  Built a new Change Set and uploaded it to production.  But, when I tried to deploy it, I got exactly the same results as above.  So, these test classes that are failing - the ones I didn't write - are in production,  They were never in my package.  I do I fix this?

sh-at-youseesh-at-yousee

As you know now the failing classes weren't in your package. However, everytime you deploy something to production all tests are run and an overall code coeverage of 75% is required (including your new code).

 

You need to update the classes in production so that your overall test coverage is above 75%. You won't be able to deploy anything until then.

 

The classes can be edited in two ways:

 

  1. Using Eclipse and the Force.com IDE
  2. Directly in the class in your Sandbox

Since you deleted the classes in your Sandbox you're looking at having to use Eclipse. I guess there's also a third way which would be to create the classes again in your Sandbox and then editing them there.

 

The errors you're seeing is because the test methods are trying to insert a record where the required field Committed_MRR__c hasn't been assigned a value.

 

I think if you get that fixed you'll be a step closer to deploying your own trigger.

 

/Søren Nødskov Hansen

This was selected as the best answer
myanceymyancey

There's a third way.  Since my trigger and test class were small, I copied them to a text file, then refreshed the sandbox getting all of the deleted test classes back, then re-created my new stuff from the text files.  So, I've recovered from the errant deletions, but I still have to fix my predecessors errors.  Or get him to fix them.

sh-at-youseesh-at-yousee

Yup, a refresh of your Sandbox will certainly get you your deleted stuff back.

 

And yes, you still need to attend to the errors as you won't be able deploy anything to production before your overall test coverage is 75% or higher.

 

/Søren Nødskov Hansen

myanceymyancey

Success!

 

I ended up deleting an installed AppExchange app that the consultants installed but was never used.  This removed all of the errors but one.  Then, I had to inactivate a pile of validation rules that check for required fields that were causing a different trigger to fail.  Once I did this, my Change Set deployed on the first try.  Turned all the val rules back on and have tested my trigger successfully in production.

 

Thank you very much for your assitance and patience on my first trigger deploy.