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
Rasha LuiceRasha Luice 

Deploying from sandbox to Production fails

The issue that I'm facing started a month and half ago. Every time one of our org user creates an opportunity, another prospection opp is automatically created. The way it worked before was, we have a Clone automatically checkbox and its value is defaulted to checked. If the user unchecked this box, the prospecting opp would not be created. And now if we check or uncheck this checkbox, the prospecting opp is created anyways.
I checked the triggers that creates the prospecting opp and found the block of code that creates the prospecting opp when the trigger is fired. On the Sandbox, when I comment that line of code and create an opportunity for testing, no matter if I check or uncheck the Clone automatically checkbox, it doesn't create the prospecting opp. And as soon as I go back to the trigger code and uncomment that line, it creates a prospecting opp if I uncheck the checkbox.
So what I decided to do is to comment the one line of code, deploy the change from Sandbox to Production, and then hide the field from the users' profiles but the deployment failed twice.
Errors I'm getting are:

System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, ContactChangeAfter: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, Individual Contact Record Type: this ID value isn't valid for the user: : [RecordTypeId] Trigger.ContactChangeAfter: line 16, column 1
Stack Trace: Class.CampaignWebServices.Test_Campaign_Dedupe: line 81, column 1

System.Exception: Assertion Failed
Stack Trace: Class.OppClone.TestCloneOrgOpp: line 113, column 1

Can you please guide me to solve this issue?

Thanks,

 
Devon SacksDevon Sacks
If your goal is to just stop the trigger from processing you can always just deactivate the trigger in sandbox and upload it to production without changes being made to it other than the active/inactive selection. This will deactive the current trigger in production. You can do this by going to Setup | Develope | Triggers | Edit after that there will be a "is Active" checkbox above your code screen. Uncheck it save and upload it from Sandbox to production. Now the trigger will not run anymore in production. If there is more to your trigger and you want to keep it and not deactivate it than can you provide a snippet of your code that is failing so we can see what else migth be causing the issue.
Rasha LuiceRasha Luice
Thanks for the reply, Devon. And yes, since the trigger might be doing something more than creating the prospecting opp, I'm not comfortable deactivating the whole trigger. Here's the error messages along with the code

Error #1
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, ContactChangeAfter: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, Individual Contact Record Type: this ID value isn't valid for the user: : [RecordTypeId] Trigger.ContactChangeAfter: line 16, column 1
Stack Trace: Class.CampaignWebServices.Test_Campaign_Dedupe: line 81, column 1
*Here's the code:
Line 16
User-added image

Line 81
User-added image

Error #2
System.Exception: Assertion Failed
Stack Trace: Class.OppClone.TestCloneOrgOpp: line 113, column 1
* Here's a snapshot of the method
User-added image

Please let me know if I'm not using this thread correctly.
Thanks!