You need to sign in to do that
Don't have an account?

I have a issue with Test class while deploying from sandbox to production
Hi
I have a issue with Test class while deploying from sandbox to production.
The same test class running pass in sandbox. but failing in production.
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY,

Here is the calss and test classes.
With Regards,
Bheemudu Neeli
I have a issue with Test class while deploying from sandbox to production.
The same test class running pass in sandbox. but failing in production.
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY,
Here is the calss and test classes.
@IsTest private with sharing class ApprovalProcessFactoryTests { private static TestMethod void testTDNewBusinessApproval() { Account supplier = new Account(); supplier.Name = 'Test Supplier'; supplier.Type = 'Supplier'; insert supplier; Case cas = new Case(); cas.AccountId = supplier.Id; cas.Type = 'Trust Deed'; cas.Insolvency_Practitioner__c = System.UserInfo.getUserId(); insert cas; ApprovalProcessFactory.ApprovalProcessWrapper wrapper = ApprovalProcessFactory.createApprovalProcess(cas.Id); wrapper.canApproveReject(); wrapper.canSubmitForApproval(); wrapper.SubmitForApproval('TD New Business'); wrapper.getReasonCodes(); // Approve as IP wrapper.canApproveReject(); wrapper.approve(false); // Approve as Mark Hamill /*List<User> users = [Select Id From User Where Name = 'Mark Hamill' and IsActive = true Limit 1]; System.runAs(users[0]) { wrapper.canApproveReject(); wrapper.reject(); }*/ } private static TestMethod void testBegbiesTDNewBusinessApproval() { list<Account> supplier = [select Id from Account where Id = :system.label.Account_Begbies_Traynor limit 1]; Case cas = new Case(); cas.AccountId = supplier[0].Id; cas.Type = 'Trust Deed'; cas.Insolvency_Practitioner__c = System.UserInfo.getUserId(); insert cas; ApprovalProcessFactory.ApprovalProcessWrapper wrapper = ApprovalProcessFactory.createApprovalProcess(cas.Id); wrapper.canApproveReject(); wrapper.canSubmitForApproval(); wrapper.SubmitForApproval('TD New Business'); wrapper.getReasonCodes(); // Approve as IP wrapper.canApproveReject(); wrapper.approve(false); // Approve as Mark Hamill /*List<User> users = [Select Id From User Where Name = 'Mark Hamill' and IsActive = true Limit 1]; System.runAs(users[0]) { wrapper.canApproveReject(); wrapper.reject(); }*/ } private static TestMethod void testIVANewBusinessApproval() { Account supplier = new Account(); supplier.Name = 'Test Supplier'; supplier.Type = 'Supplier'; insert supplier; QResponse__c qr = new QResponse__c(); qr.Status__c = 'Completed'; qr.All_fields_complete__c = true; insert qr; Case cas = new Case(); cas.AccountId = supplier.Id; cas.Type = 'IVA'; cas.Insolvency_Practitioner__c = System.UserInfo.getUserId(); insert cas; Case cas2 = new Case(); cas2.AccountId = supplier.Id; cas2.Type = 'Trust Deed'; cas2.Insolvency_Practitioner__c = System.UserInfo.getUserId(); cas2.Money_Laundering_Q__c = qr.Id; insert cas2; Case_Approval_Step__c appr = new Case_Approval_Step__c(); appr.Case__c = cas2.Id; appr.Step_Number__c = 1; appr.Status__c = 'Waiting for approver'; appr.Approval_Type__c = 'Money Laundering'; insert appr; ApprovalProcessFactory.ApprovalProcessWrapper wrapper = ApprovalProcessFactory.createApprovalProcess(cas.Id); wrapper.canApproveReject(); wrapper.canSubmitForApproval(); wrapper.SubmitForApproval('New Business'); wrapper.getReasonCodes(); // Approve first stage approval system.assertEquals(true, wrapper.canApproveReject()); wrapper.approve(false); // Approve as IP system.assertEquals(true, wrapper.canApproveReject()); wrapper.approve(false); //Money laundering on Case ApprovalProcessFactory.ApprovalProcessWrapper wrapper2 = ApprovalProcessFactory.createApprovalProcess(cas2.Id); wrapper2.SubmitForApproval('Money Laundering'); wrapper2.getReasonCodes(); wrapper2.canApproveReject(); wrapper2.approve(false); //Money Laundering on custom case cas.Money_Laundering_Q__c=qr.Id; update cas; appr.Case__c = cas.Id; update appr; ApprovalProcessFactory.ApprovalProcessWrapper wrapper3 = ApprovalProcessFactory.createApprovalProcess(cas.Id); wrapper3.canApproveReject(); wrapper3.canSubmitForApproval(); wrapper3.SubmitForApproval('Money Laundering'); wrapper3.getReasonCodes(); // Approve first stage approval wrapper3.canApproveReject(); wrapper3.approve(false); } private static TestMethod void testCustomCaseIVANewBusinessApproval() { Account supplier = new Account(); supplier.Name = 'Test Supplier'; supplier.Type = 'Supplier'; insert supplier; QResponse__c qr = new QResponse__c(); qr.Status__c = 'Completed'; qr.All_fields_complete__c = true; insert qr; CustomCase__c cc = new CustomCase__c(); cc.Partner__c=System.Label.Account_Invocas; cc.Product__c='IVA'; cc.Case_Type__c='IVA'; cc.Status__c='IVA MOC'; cc.Process_Step__c='Arranging MOC'; cc.Bond_Level__c=1500; cc.Date_of_Nominee_Appointment__c=date.today(); cc.Date_Signed_IVA_Proposal_Received__c=date.today(); cc.Money_Laundering_Q__c = qr.Id; insert cc; CustomCase__c cc2 = new CustomCase__c(); cc2.Partner__c=System.Label.Account_Invocas; cc2.Product__c='Trust Deed'; cc2.Case_Type__c='Trust Deed'; cc2.Status__c='IVA MOC'; cc2.Process_Step__c='Arranging MOC'; cc2.Bond_Level__c=1500; cc2.Date_of_Nominee_Appointment__c=date.today(); cc2.Date_Signed_IVA_Proposal_Received__c=date.today(); cc2.Money_Laundering_Q__c = qr.Id; insert cc2; Case_Approval_Step__c appr = new Case_Approval_Step__c(); appr.CustomCase__c = cc.Id; appr.Step_Number__c = 1; appr.Status__c = 'Waiting for approver'; appr.Approval_Type__c = 'Money Laundering'; insert appr; //ApprovalProcessFactory.ApprovalProcessWrapper wrapper = ApprovalProcessFactory.createApprovalProcess(cc.Id); ApprovalProcessFactory.ApprovalProcessWrapper wrapper = ApprovalProcessFactory.createApprovalProcess(cc.Id, 'Money Laundering'); wrapper.getApprovalType(); wrapper.canApproveReject(); wrapper.getCurrentStep(); wrapper.getSObject(); wrapper.getSObjectName(); wrapper.getCurrentStep(); wrapper.getReasonCodes(); wrapper.canSubmitForApproval(); //wrapper.SubmitForApproval('New Business'); wrapper.SubmitForApproval('Money Laundering'); wrapper.canApproveReject(); wrapper.approve(false); ApprovalProcessFactory.ApprovalProcessWrapper wrapper1 = ApprovalProcessFactory.createApprovalProcess(cc.Id, 'IVA New Business'); wrapper1.SubmitForApproval('IVA New Business'); wrapper1.getReasonCodes(); wrapper1.canApproveReject(); wrapper1.approve(false); ApprovalProcessFactory.ApprovalProcessWrapper wrapper2 = ApprovalProcessFactory.createApprovalProcess(cc2.Id, 'Money Laundering'); wrapper2.SubmitForApproval('Money Laundering'); wrapper2.getReasonCodes(); wrapper2.canApproveReject(); } private static TestMethod void testAnnualReviewApproval() { Account supplier = new Account(); supplier.Name = 'Test Supplier'; supplier.Type = 'Supplier'; insert supplier; list<Account> supplier1 = [select Id from Account where id = :System.Label.Account_Mazars]; Case cas = new Case(); cas.AccountId = supplier.Id; cas.Insolvency_Practitioner__c = System.UserInfo.getUserId(); insert cas; Case cas1 = new Case(); cas1.AccountId = supplier1[0].Id; cas1.Insolvency_Practitioner__c = System.UserInfo.getUserId(); insert cas1; Annual_Review__c ar = new Annual_Review__c(); ar.Case__c = cas.Id; ar.Insolvency_Practitioner__c = System.UserInfo.getUserId(); ar.Increase_Case_Budget__c = 100; insert ar; Annual_Review__c ar1 = new Annual_Review__c(); ar1.Case__c = cas1.Id; ar1.Insolvency_Practitioner__c = System.UserInfo.getUserId(); insert ar1; ApprovalProcessFactory.ApprovalProcessWrapper wrapper = ApprovalProcessFactory.createApprovalProcess(ar.Id); wrapper.canSubmitForApproval(); wrapper.SubmitForApproval('Annual Review'); wrapper.getReasonCodes(); // Attempt to approve - should result in error wrapper.approve(false); // Approve as Jill Glen//Now Sam Mcginness List<User> users = [Select Id, Bypass_VR__c From User Where Id =:System.Label.User_AR_First_Approver]; users[0].Bypass_VR__c=true; update users; System.runAs(users[0]) { wrapper.canApproveReject(); wrapper.approve(false); } // Approve as IP wrapper.canApproveReject(); wrapper.approve(true); ApprovalProcessFactory.ApprovalProcessWrapper wrapper1 = ApprovalProcessFactory.createApprovalProcess(ar1.Id); wrapper1.canSubmitForApproval(); wrapper1.SubmitForApproval('Annual Review'); wrapper1.getReasonCodes(); // Attempt to approve - should result in error wrapper1.approve(false); // Approve as Jill Glen//Now Sam Mcginness System.runAs(users[0]) { wrapper1.canApproveReject(); wrapper1.approve(false); } // Approve as IP wrapper1.canApproveReject(); wrapper1.approve(true); } private static TestMethod void testGenericApproval() { Account supplier = new Account(); supplier.Name = 'Test Supplier'; supplier.Type = 'Supplier'; insert supplier; Case cas = new Case(); cas.AccountId = supplier.Id; cas.Insolvency_Practitioner__c = System.UserInfo.getUserId(); insert cas; ApprovalProcessFactory.ApprovalProcessWrapper wrapper = ApprovalProcessFactory.createApprovalProcess(cas.Id); wrapper.canSubmitForApproval(); wrapper.SubmitForApproval('Generic'); wrapper.getReasonCodes(); // Approve as IP wrapper.canApproveReject(); wrapper.approve(false); wrapper.reject(); wrapper.getReasonCodes(); wrapper.getSObjectType(); wrapper.getRecordType(); ApprovalProcessFactory.ApprovalProcessWrapper wrapper2 = ApprovalProcessFactory.createApprovalProcess(cas.Id); wrapper2.SubmitForApproval('Money Laundering'); wrapper2.getReasonCodes(); } private static TestMethod void testEthicsApprovals() { Account supplier = new Account(); supplier.Name = 'Test Supplier'; supplier.Type = 'Supplier'; insert supplier; QResponse__c qr1 = new QResponse__c(); qr1.Status__c = 'Completed'; qr1.All_fields_complete__c = true; insert qr1; QResponse__c qr2 = new QResponse__c(); qr2.Status__c = 'Completed'; qr2.All_fields_complete__c = true; insert qr2; CustomCase__c cc = new CustomCase__c(); cc.Partner__c=System.Label.Account_Invocas; cc.Product__c='IVA'; cc.Case_Type__c='IVA'; cc.Status__c='IVA MOC'; cc.Process_Step__c='Arranging MOC'; cc.Bond_Level__c=1500; cc.Date_of_Nominee_Appointment__c=date.today(); cc.Date_Signed_IVA_Proposal_Received__c=date.today(); cc.Ethics_Q__c = qr1.Id; insert cc; Case_Approval_Step__c appr1 = new Case_Approval_Step__c(); appr1.CustomCase__c = cc.Id; appr1.Step_Number__c = 1; appr1.Status__c = 'Waiting for approver'; appr1.Approval_Type__c = 'Ethics Checklist'; insert appr1; Case cas = new Case(); cas.AccountId = supplier.Id; cas.Insolvency_Practitioner__c = System.UserInfo.getUserId(); cas.Ethics_Q__c = qr2.Id; insert cas; Case_Approval_Step__c appr2 = new Case_Approval_Step__c(); appr2.Case__c = cas.Id; appr2.Step_Number__c = 1; appr2.Status__c = 'Waiting for approver'; appr2.Approval_Type__c = 'Ethics Checklist'; insert appr2; ApprovalProcessFactory.ApprovalProcessWrapper wrapper = ApprovalProcessFactory.createApprovalProcess(cc.Id); wrapper.SubmitForApproval('Ethics Checklist'); wrapper.getReasonCodes(); wrapper.canApproveReject(); wrapper.approve(false); ApprovalProcessFactory.ApprovalProcessWrapper wrapper2 = ApprovalProcessFactory.createApprovalProcess(cas.Id); wrapper2.SubmitForApproval('Ethics Checklist'); wrapper2.getReasonCodes(); wrapper2.canApproveReject(); wrapper2.approve(false); } private static TestMethod void testFailureApproval() { Account supplier = new Account(); supplier.Name = 'Test Supplier'; supplier.Type = 'Supplier'; insert supplier; Case cas = new Case(); cas.AccountId = supplier.Id; cas.Insolvency_Practitioner__c = System.UserInfo.getUserId(); insert cas; ApprovalProcessFactory.ApprovalProcessWrapper wrapper = ApprovalProcessFactory.createApprovalProcess(cas.Id); wrapper.SubmitForApproval('Failure'); wrapper.getReasonCodes(); wrapper.approve(false); //wrapper.reject(); List<User> testUser = [Select Id From User Where ProfileId=:System.Label.ProfId_Services_Team_Leader and IsActive = true Limit 1]; System.runAs(testUser[0]) { wrapper.canApproveReject(); wrapper.approve(false); } } private static TestMethod void testSEQNewBusinessApproval() { Account supplier = new Account(); supplier.Name = 'Test Supplier'; supplier.Type = 'Supplier'; insert supplier; QResponse__c qr = new QResponse__c(); qr.Status__c = 'Completed'; qr.All_fields_complete__c = true; insert qr; CustomCase__c cc = new CustomCase__c(); cc.Partner__c=System.Label.Account_Invocas; cc.Product__c='Sequestration'; cc.Case_Type__c='Sequestration'; insert cc; Case_Approval_Step__c appr = new Case_Approval_Step__c(); appr.CustomCase__c = cc.Id; appr.Step_Number__c = 1; appr.Status__c = 'Waiting for approver'; appr.Approval_Type__c = 'Sequestration New Business'; insert appr; //ApprovalProcessFactory.ApprovalProcessWrapper wrapper = ApprovalProcessFactory.createApprovalProcess(cc.Id); ApprovalProcessFactory.ApprovalProcessWrapper wrapper = ApprovalProcessFactory.createApprovalProcess(cc.Id, 'Sequestration New Business'); wrapper.getApprovalType(); wrapper.canApproveReject(); wrapper.getCurrentStep(); wrapper.getReasonCodes(); wrapper.SubmitForApproval('Sequestration New Business'); wrapper.approve(false); } private static TestMethod void testSEQCasefileChecklist() { Account supplier = new Account(); supplier.Name = 'Test Supplier'; supplier.Type = 'Supplier'; insert supplier; QResponse__c qr = new QResponse__c(); qr.Status__c = 'Completed'; qr.All_fields_complete__c = true; insert qr; CustomCase__c cc = new CustomCase__c(); cc.Partner__c=System.Label.Account_Invocas; cc.Product__c='Sequestration'; cc.Case_Type__c='Sequestration'; cc.SEQ_Case_File_CL__c = qr.Id; insert cc; Case_Approval_Step__c appr = new Case_Approval_Step__c(); appr.CustomCase__c = cc.Id; appr.Step_Number__c = 1; appr.Status__c = 'Waiting for approver'; appr.Approval_Type__c = 'Sequestration Casefile Checklist'; insert appr; //ApprovalProcessFactory.ApprovalProcessWrapper wrapper = ApprovalProcessFactory.createApprovalProcess(cc.Id); ApprovalProcessFactory.ApprovalProcessWrapper wrapper = ApprovalProcessFactory.createApprovalProcess(cc.Id, 'Sequestration Casefile Checklist'); wrapper.getApprovalType(); List<User> testUser = [Select Id From User Where ProfileId=:System.Label.ProfId_Services_Team_Leader and IsActive = true Limit 1]; System.runAs(testUser[0]) { wrapper.canApproveReject(); } wrapper.canApproveReject(); wrapper.getCurrentStep(); wrapper.getReasonCodes(); wrapper.SubmitForApproval('Sequestration Casefile Checklist'); //wrapper.finaliseApproval(1); wrapper.approve(false); } private static TestMethod void testQualityOfWorkApproval() { Account supplier = new Account(); supplier.Name = 'Test Supplier'; supplier.Type = 'Supplier'; insert supplier; QResponse__c qr = new QResponse__c(); qr.Status__c = 'Completed'; qr.All_fields_complete__c = true; insert qr; Case cas = new Case(); cas.AccountId = supplier.Id; cas.Type = 'Trust Deed'; cas.Insolvency_Practitioner__c = System.UserInfo.getUserId(); cas.PTD_Quality_Of_Work_CL__c = qr.Id; insert cas; Case_Approval_Step__c appr = new Case_Approval_Step__c(); appr.Case__c = cas.Id; appr.Step_Number__c = 1; appr.Status__c = 'Waiting for approver'; appr.Approval_Type__c = 'Quality Of Work'; insert appr; ApprovalProcessFactory.ApprovalProcessWrapper wrapper = ApprovalProcessFactory.createApprovalProcess(cas.Id); wrapper.canApproveReject(); wrapper.canSubmitForApproval(); wrapper.SubmitForApproval('Quality Of Work'); wrapper.getReasonCodes(); // Approve first stage approval List<User> testUser = [Select Id From User Where Id=:System.Label.Quality_Of_Work_Approver]; System.runAs(testUser[0]) { wrapper.canApproveReject(); wrapper.approve(false); } // Approve as IP //system.assertEquals(true, wrapper.canApproveReject()); //wrapper.approve(false); } private static TestMethod void testccQualityOfWorkApproval() { QResponse__c qr = new QResponse__c(); qr.Status__c = 'Completed'; qr.All_fields_complete__c = true; insert qr; CustomCase__c cc = new CustomCase__c(); cc.Partner__c=System.Label.Account_Invocas; cc.Product__c='IVA'; cc.Case_Type__c='IVA'; cc.IVA_Quality_Of_Work_CL__c = qr.Id; insert cc; Case_Approval_Step__c appr = new Case_Approval_Step__c(); appr.CustomCase__c = cc.Id; appr.Step_Number__c = 1; appr.Status__c = 'Waiting for approver'; appr.Approval_Type__c = 'Quality Of Work'; insert appr; ApprovalProcessFactory.ApprovalProcessWrapper wrapper = ApprovalProcessFactory.createApprovalProcess(cc.Id); wrapper.canApproveReject(); wrapper.canSubmitForApproval(); wrapper.SubmitForApproval('Quality Of Work'); wrapper.getReasonCodes(); // Approve first stage approval List<User> testUser = [Select Id From User Where Id=:System.Label.Quality_Of_Work_Approver]; System.runAs(testUser[0]) { wrapper.canApproveReject(); wrapper.approve(false); } } }
With Regards,
Bheemudu Neeli
System.UserInfo.getUserId();
Try to create the user within the test class and then reference the ID of the user you just created in the test class instead.