I've been trying to create and implement an Apex Trigger/Apex Test Class for the Asset object to automatically populate an Asset custom lookup field, "Partner_Client__c", with the same information as is in the Account custom lookup field "Partner_Client_Name__c".
Apex Trigger "Asset_Autopopulate":
trigger Asset_Autopopulate on Asset (before insert, before update) {
Set<String> clientIds = new Set<String>();
for (Asset ass : Trigger.new) {
clientIds.add(ass.AccountId);
}
List<Account> clients = [SELECT Id, Partner_Client_Name__r.Id FROM Account WHERE Id =: clientIds];
Map<String, Asset> assetMap = new Map<String, Asset>();
for (Asset ass : Trigger.new) {
assetMap.put(ass.AccountId, ass);
}
for (Account acc : clients) {
if (assetMap.containsKey(acc.Id)) {
assetMap.get(acc.Id).Partner_Client__r.Id = acc.Partner_Client_Name__r.Id;
}
}
update clients;
}
Associated Apex Test Class "Asset_Autopopulate_Test":
@isTest
private class Asset_Autopopulate_Test {
static testMethod void Asset_Autopopulate_TestMethod() {
Account acc = new Account();
acc.Name = 'Test Client #1';
acc.Rating = 'Not Started';
acc.OwnerId = '005E00000050KGS';
acc.Website = 'TestLeads-Company#1.com';
acc.Phone = '0000000000';
acc.Other_Phone__c = '1111111111';
acc.Industry = 'Other';
acc.Description = 'Test Client #1 Description';
acc.Partner_Client_Name__c = '001E000001EczmwIAB';
insert acc;
Asset ass = new Asset();
ass.Name = 'Test Asset #1';
ass.AccountId = acc.Id;
// ass.OwnerId = '005E00000050KGS';
test.startTest();
insert ass;
update ass;
test.stopTest();
}
}
The trigger itself seems to be working fine, and most of the Test Class seems to be working, but every time I attempt to validate these two and deploy them, I am met with this failure condition:
Anything that could help me better understand how/why this is happening and what measures I should take in order to solve this problem would be greatly appreciated and apologies for my liberal use of commas.