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

Deployment issue for Trigger & Test Class
Hi everyone- I need to deploy an apex trigger and it's corresponding test class into my production instance. Here's the code for the trigger:
trigger USERBusinessUnit on Account (before insert, before update) { // create a set of all the unique ownerIds Set<Id> ownerIds = new Set<Id>(); for (Account a : Trigger.new) ownerIds.add(a.OwnerId); // query for all the User records for the unique userIds in the records // create a map for a lookup / hash table for the user info Map<Id, User> owners = new Map<Id, User>([Select USER.Business_Unit__c from User Where Id in :ownerIds]); // iterate over the list of records being processed in the trigger and // set the Owner's Business Unit before being inserted or updated for (Account a : Trigger.new) a.Business_Unit__c = owners.get(a.OwnerId).Business_Unit__c; }
And here is the test class that compiles (and works):
@isTest private class USERBusinessUnitTriggerTest { private static TestMethod void testUSERBusinessUnitMethod() { User u = [Select id from User where id =: Userinfo.getuserId()]; u.Business_Unit__c = 'Test BU'; update u; test.startTest(); system.runAs(u) { Account a = new Account(Name = 'Test Account'); //fill all mandatory field of account before insert if any insert a; system.assertEquals(u.Business_Unit__c , a.Business_Unit__c); } test.stopTest(); } }
Both the user & account objects have the Business_Unit__c field (picklist field with either a value of P or E ). When i went to deploy the change set I got the following error:
API NameTypeLineColumnProblem
USERBusinessUnitTriggerTest.testUSERBusinessUnitMethod() | Class | 18 | 4 | Failure Message: "System.AssertException: Assertion Failed: Expected: Test BU, Actual: null", Failure Stack Trace: "Class.USERBusinessUnitTriggerTest.testUSERBusinessUnitMethod: line 18, column 4 External entry point" |
Can anybody please help? Thanks!
please change it to this