+ Start a Discussion

Help with Eclipse error (Deployment problem)

Hi all,


We have created a custom object with a couple of triggers (before and after insert) and some Apex classes, one of them called from the after insert trigger and the other is the test class to test it all.


Within our Sandbox environment, we run all tests and get an 84% code coverage and no failures.


However, when we try to deploy to production, we get an odd error on Eclipse, an error on line 48 which is where we Insert the new object (for which there are 2 triggers, the after insert one calling another Apex Class). The error we get says:



System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, CreaCrompromisos: execution of AfterInsert


All I can say is that within the AfterInsert trigger, we call a class passing the custom object ID so within it, we can access this object and update it. Maybe the issue is this, that within an AfterInsert trigger, you can´t update the calling object (surprisingly, tests within Salesforce do not show errors!). If this is so, how can we work around this? We are calling a process that takes some time and processes a few records, so we want to capture the start time, end time and number of records processed. Any ideas?








Do your test classes contain any hardcoded Id strings?  If so, are those Ids valid in production, or only in your Sandbox org?


The best practice is to insert all data you need to access in a test method at the beginning of the test method, and then to call Test.startTest() before your actual test code begins.


Hi Jon,


Thanks for your suggestions. My code only contains the hardcoding of 2 record types that are correct (ie: same IDs in Production and Sandbox). I will check startTest() and see the issue is that in my case the testing really happens when you create the date (I am testing before and after insert triggers), so it is difficult to decouple the inserting of the data with the test itself.


I feel the problem is quite possibly the fact that I am trying to update the calling record from within an after insert trigger, can that be the problem? The error is stating: "CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY"


How do you suggest I can investigate this further to reach a resolution? I am a bit puzzled by the fact that tests within SF Sandbox run Ok and when migrating I get this error (the logical thinking is, as you stated, that there is something that works on the Sandbox but not in Production)...


Thanks again,