You need to sign in to do that
Don't have an account?
Olavo Zapata
Hi all,
I'm having a hard time running an Apex Test for a trigger that I'm trying to use.
The trigger basically matches the External ID of a Custom Object with the same External ID from Contract ID, to bring me the Account ID in the Custom Object.
What Test needs to do is test this trigger, so I can put it into production. But is giving me the following error:
The trigger and the Test are the following:
Anyone could identify what the error could be? I'm a beginner on this apex things.
Thanks.
Error in the Apex Test to insert a register in Contract (Invalid Status)
Hi all,
I'm having a hard time running an Apex Test for a trigger that I'm trying to use.
The trigger basically matches the External ID of a Custom Object with the same External ID from Contract ID, to bring me the Account ID in the Custom Object.
What Test needs to do is test this trigger, so I can put it into production. But is giving me the following error:
System.DmlException: Insert failed. First exception on row 0; first error: FAILED_ACTIVATION, Choose a valid contract status and save your changes. Ask your admin for details.: [Status]
Class.UpdateAccountId2.testWithExistingAccount: line 31, column 1
The trigger and the Test are the following:
/** # New Version of nKPI Trigger **/ trigger UpdateAccountId2 on nKPI__c (before update, before insert) { Map<String, nKPI__c> tintgreMap = new Map<String, nKPI__c>(); for(nKPI__c ti : trigger.new) { if(trigger.isInsert || (trigger.isUpdate && ti.RDStationID__c != trigger.oldMap.get(ti.Id).rdstationid__c)) { tintgreMap.put(ti.rdstationid__c, ti); } } if(tintgreMap == null) return; Map<String, Contract> accountMap = new Map<String, Contract>(); for (Contract account : [Select AccountId,externalCode__c FROM Contract WHERE Product_Group__c = 'RD Station' AND externalCode__c = :tintgreMap.KeySet()]) { accountMap.put(account.externalCode__c, account); } if(accountMap == null) return; for(nKPI__c tiRecord : tintgreMap.Values()) { tiRecord.Account__c = accountMap.get(tiRecord.rdstationid__c).AccountId; } } --------------------------------------------------- TEST @isTest(OnInstall=true) private class UpdateAccountId2 { public static List<Contract> contractsList; public static List<nKPI__c> kpiList; public static String rdstation_id_account1; static void init(){ contractsList = new List<Contract>(); kpiList = new List<nKPI__c>(); rdstation_id_account1 = '100'; kpiList.add(new nKPI__c( rdstationid__c = rdstation_id_account1 )); } /** Test with an existing account **/ static testMethod void testWithExistingAccount() { init(); Test.startTest(); contractsList.add(new Contract( Name = 'Test', internalid__c = '1000001', Status = '0 - Trial', externalCode__c = rdstation_id_account1 )); insert contractsList; insert kpiList; kpiList = [ SELECT Id, Account__c FROM nKPI__c WHERE Id = :kpiList[0].Id ]; // Verification System.assertEquals(kpiList[0].Account__c, contractsList[0].Id); Test.stopTest(); } }
Anyone could identify what the error could be? I'm a beginner on this apex things.
Thanks.
All Answers
Also that means inserting a new Account in order to get an AccountId.
Hi Colin,
I tried in this way as well and get the same error.You mean like this in line 54:
Thanks for your help, but I tried:
Look these are my Contract's Status:
My friend now works! So, always I need to create a contract through the Apex I need to do with one status of the Draft category?
Thanks for your help!