You need to sign in to do that
Don't have an account?
Help with Test class for Trigger
Can someone help me with a test class for the following. Would like to put together a "public WITHOUT SHARING" test class if possible. Thank you.
trigger caseToAM on Case (before insert) {
Set<ID> accountIDs = new Set<ID>();
for (Case c : trigger.new) {
//build a set of unique account ids associated to the case(s) being created
if (c.AccountId != null && c.RecordTypeId == '012R00000004tyC') {
accountIDs.add(c.AccountId);
}
}
//get the account manager id for all accounts affected
List<Account> lAccounts = [SELECT Id, Name, Account_Manager__r.Id FROM Account WHERE Id in :accountIDs];
//loop through the cases again and assign the account manager to the case
for (Case c : trigger.new) {
//change the owner to the account manager
for (Account a : lAccounts) {
if (c.AccountId == a.Id) {
if(a.Account_Manager__r.Id != NULL)
c.OwnerId = a.Account_Manager__r.Id;
else
c.OwnerId = UserInfo.getUserId();
break;
}
}
}
}
Hi,
Below is the Test class as per your requirement.
Test Class:
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.
Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator
My Blog:- http://mrjavascript.blogspot.in/