You need to sign in to do that
Don't have an account?
jrosser1.39050288155405E12
Apex Class, For Inserting Account Teams
I created a trigger on Custom Object TSG__c to insert a record into the account team when the record is updated. The trigger works fine, now I am just trying to write the class.
I am inserting records for 200 Accounts, 200 Users and 200 AccountTeamMemebers and referencing the ID's from Accounts,Users as the Account Team is being created, but I do not know how to tie it all back to gether.
Any Ideas?
@isTest
private class addAccountTeam {
@isTest
static void test_checkTSGAccounTeamInsert() {
// Create the Acounts
List<Account> accList = new List<Account>();
for (Integer i = 0; i < 200; i++) {
Account newAcc = new Account(Name='Test' + i,P21_CompanyCustomer_ID__c = '1-10009' + i );
accList.add(newAcc);
}
insert accList;
// create the TSGs
List<TSG__c> tsgList = new List<TSG__c>();
for (Integer i = 0; i < 200; i++) {
TSG__c newTSG = new TSG__c(Name='Test' + i,email_address__c ='Test' + i + '@Tri-ed.com',
P21_CompanyCustomer_ID__c = accList[i].P21_CompanyCustomer_ID__c);
tsgList.add(newTSG);
}
insert tsgList;
// create the Users
List<User> userList = new List<User>();
for (Integer i = 0; i< 200; i++) {
// observe the same name for Opp and TSG
USer newUser = new User(lastname = 'Test',Alias = 'Test',TimeZoneSidKey = 'GMT',
LocaleSidKey = 'eu_ES',EmailEncodingKey = 'ISO-8859-1',
ProfileId = '00ei0000000TYak',LanguageLocaleKey = 'en_US',
userName='Test' + i + '@Tri-ed.com',email='Test' + i + '@Tri-ed.com');
userList.add(newUser);
}
insert userList;
//Create the AccountTeam
List<AccountTeamMember> teamList = new List<AccountTeamMember>();
For (Integer i = 0; i< 200; i++) {
AccountTeamMember newTeam = new AccountTeamMember(AccountId = accList[i].ID,TeamMemberRole = 'Technical Sales',UserId = userList[i].ID);
teamList.add(newTeam);
}
insert teamList;
//Create the AccountTeamShare
List<AccountShare> shareList = new List<AccountShare>();
For (Integer i = 0; i< 200; i++) {
AccountShare newShare = new AccountShare(AccountId = accList[i].ID,UserOrGroupId = userList[i].ID,CaseAccessLevel = 'Edit',AccountAccessLevel = 'Edit',OpportunityAccessLevel = 'Edit');
shareList.add(newShare);
}
insert shareList;
//Check to Make Sure records Match Up.
teamList = [Select AccountID,UserId,TeamMemberRole from AccountTeamMember order by ID];
accList = [Select ID,P21_CompanyCustomer_ID__c from Account order by ID];
For (AccountTeamMember team: teamList) {
For (Account acct: accList) {
System.assertEquals(team.AccountID,acct.ID);
}
}
}
}
I am inserting records for 200 Accounts, 200 Users and 200 AccountTeamMemebers and referencing the ID's from Accounts,Users as the Account Team is being created, but I do not know how to tie it all back to gether.
Any Ideas?
@isTest
private class addAccountTeam {
@isTest
static void test_checkTSGAccounTeamInsert() {
// Create the Acounts
List<Account> accList = new List<Account>();
for (Integer i = 0; i < 200; i++) {
Account newAcc = new Account(Name='Test' + i,P21_CompanyCustomer_ID__c = '1-10009' + i );
accList.add(newAcc);
}
insert accList;
// create the TSGs
List<TSG__c> tsgList = new List<TSG__c>();
for (Integer i = 0; i < 200; i++) {
TSG__c newTSG = new TSG__c(Name='Test' + i,email_address__c ='Test' + i + '@Tri-ed.com',
P21_CompanyCustomer_ID__c = accList[i].P21_CompanyCustomer_ID__c);
tsgList.add(newTSG);
}
insert tsgList;
// create the Users
List<User> userList = new List<User>();
for (Integer i = 0; i< 200; i++) {
// observe the same name for Opp and TSG
USer newUser = new User(lastname = 'Test',Alias = 'Test',TimeZoneSidKey = 'GMT',
LocaleSidKey = 'eu_ES',EmailEncodingKey = 'ISO-8859-1',
ProfileId = '00ei0000000TYak',LanguageLocaleKey = 'en_US',
userName='Test' + i + '@Tri-ed.com',email='Test' + i + '@Tri-ed.com');
userList.add(newUser);
}
insert userList;
//Create the AccountTeam
List<AccountTeamMember> teamList = new List<AccountTeamMember>();
For (Integer i = 0; i< 200; i++) {
AccountTeamMember newTeam = new AccountTeamMember(AccountId = accList[i].ID,TeamMemberRole = 'Technical Sales',UserId = userList[i].ID);
teamList.add(newTeam);
}
insert teamList;
//Create the AccountTeamShare
List<AccountShare> shareList = new List<AccountShare>();
For (Integer i = 0; i< 200; i++) {
AccountShare newShare = new AccountShare(AccountId = accList[i].ID,UserOrGroupId = userList[i].ID,CaseAccessLevel = 'Edit',AccountAccessLevel = 'Edit',OpportunityAccessLevel = 'Edit');
shareList.add(newShare);
}
insert shareList;
//Check to Make Sure records Match Up.
teamList = [Select AccountID,UserId,TeamMemberRole from AccountTeamMember order by ID];
accList = [Select ID,P21_CompanyCustomer_ID__c from Account order by ID];
For (AccountTeamMember team: teamList) {
For (Account acct: accList) {
System.assertEquals(team.AccountID,acct.ID);
}
}
}
}
Your assert is "asserting" that all AccountTeamMembers are members of All Accounts.
Also, you will need to add additional asserts to ensure the logic in your trigger is running properlyTry changing it around to the following:
All Answers
I cannot seem to get them to sync up.
Your assert is "asserting" that all AccountTeamMembers are members of All Accounts.
Also, you will need to add additional asserts to ensure the logic in your trigger is running properlyTry changing it around to the following:
Thanks again.