You need to sign in to do that
Don't have an account?
Guru 91
Test class for Account class
Hi Everyone,
can you please help me with test class
public without sharing class AccountHelperUtility {
//update account area fields
public static void insertUpdateAccountAreaFields(List<Account> AccountList, Map<ID,sObject> AccountMapOld) {
for(Account account:AccountList) {
Account accountOld = AccountMapOld == null ? null : (Account)AccountMapOld.get(account.id);
populateValuesBeforeInsertUpdate(account, accountOld, 'Planned_Retention_Tsubo__c', 'Planned_Retention_SF__c', 'Planned_Retention_SM__c');
populateValuesBeforeInsertUpdate(account, accountOld, 'Customer_Total_Footprint_Wallet_Tsubo__c', 'Customer_Total_Footprint_Wallet_SF__c', 'Customer_Total_Footprint_Wallet_SM__c');
}
}
static void populateValuesBeforeInsertUpdate(Account account, Account accountOld, String Tsubo, String SF, String SM) {
Boolean isUpdate = accountOld == null ? false : true;
if(account.get(SF) != null && String.valueOf(account.get(SF))!= '' && (!isUpdate || Integer.valueOf(account.get(SF)) != Integer.valueOf(accountOld.get(SF))) ){
account.put(Tsubo , UOMCalculation.getTsuboFromSf((decimal)account.get(SF)));
account.put(SM , UOMCalculation.getM2FromSf((decimal)account.get(SF)));
}else if(account.get(SM) != null && String.valueOf(account.get(SM))!= '' && (!isUpdate || Integer.valueOf(account.get(SM)) != Integer.valueOf(accountOld.get(SM))) ){
Decimal sqFt = UOMCalculation.getSfFromM2((decimal)account.get(SM));
account.put(Tsubo , UOMCalculation.getTsuboFromSf(sqFt));
account.put(SF , sqFt);
}else if(account.get(Tsubo) != null && String.valueOf(account.get(Tsubo))!= '' && (!isUpdate || Integer.valueOf(account.get(Tsubo)) != Integer.valueOf(accountOld.get(Tsubo))) ) {
Decimal sqFt = UOMCalculation.getSfFromTsubo((decimal)account.get(Tsubo));
account.put(SM , UOMCalculation.getM2FromSf(sqFt));
account.put(SF , sqFt);
}
}
//Added for T-131999
public static void removeTeamMembers(Map<Id,Account> accountNewMap, Map<Id,Account> accountOldMap){
map<Id,Id> accIdToGCSOfficerMap = new map<Id,Id>();
list<AccountTeamMember> teamMembersToBeDeleted = new list<AccountTeamMember>();
for(Account acc : accountNewMap.values()){
if((acc.GCS_Account_Officer__c != null &&
acc.GCS_Account_Officer__c != accountOldMap.get(acc.Id).GCS_Account_Officer__c)){
accIdToGCSOfficerMap.put(acc.Id,acc.GCS_Account_Officer__c);
}
}
if(accIdToGCSOfficerMap.size() > 0 ){
for(AccountTeamMember accTeamMember : [Select Id,UserId,AccountId from AccountTeamMember where AccountId IN :
accIdToGCSOfficerMap.keySet()]){
if(accTeamMember.AccountId != null && accIdToGCSOfficerMap.containsKey(accTeamMember.AccountId) &&
accTeamMember.UserId != null && accIdToGCSOfficerMap.get(accTeamMember.AccountId) == accTeamMember.UserId){
teamMembersToBeDeleted.add(accTeamMember);
}
}
}
if(teamMembersToBeDeleted.size() > 0){
delete teamMembersToBeDeleted;
}
}
}
can you please help me with test class
public without sharing class AccountHelperUtility {
//update account area fields
public static void insertUpdateAccountAreaFields(List<Account> AccountList, Map<ID,sObject> AccountMapOld) {
for(Account account:AccountList) {
Account accountOld = AccountMapOld == null ? null : (Account)AccountMapOld.get(account.id);
populateValuesBeforeInsertUpdate(account, accountOld, 'Planned_Retention_Tsubo__c', 'Planned_Retention_SF__c', 'Planned_Retention_SM__c');
populateValuesBeforeInsertUpdate(account, accountOld, 'Customer_Total_Footprint_Wallet_Tsubo__c', 'Customer_Total_Footprint_Wallet_SF__c', 'Customer_Total_Footprint_Wallet_SM__c');
}
}
static void populateValuesBeforeInsertUpdate(Account account, Account accountOld, String Tsubo, String SF, String SM) {
Boolean isUpdate = accountOld == null ? false : true;
if(account.get(SF) != null && String.valueOf(account.get(SF))!= '' && (!isUpdate || Integer.valueOf(account.get(SF)) != Integer.valueOf(accountOld.get(SF))) ){
account.put(Tsubo , UOMCalculation.getTsuboFromSf((decimal)account.get(SF)));
account.put(SM , UOMCalculation.getM2FromSf((decimal)account.get(SF)));
}else if(account.get(SM) != null && String.valueOf(account.get(SM))!= '' && (!isUpdate || Integer.valueOf(account.get(SM)) != Integer.valueOf(accountOld.get(SM))) ){
Decimal sqFt = UOMCalculation.getSfFromM2((decimal)account.get(SM));
account.put(Tsubo , UOMCalculation.getTsuboFromSf(sqFt));
account.put(SF , sqFt);
}else if(account.get(Tsubo) != null && String.valueOf(account.get(Tsubo))!= '' && (!isUpdate || Integer.valueOf(account.get(Tsubo)) != Integer.valueOf(accountOld.get(Tsubo))) ) {
Decimal sqFt = UOMCalculation.getSfFromTsubo((decimal)account.get(Tsubo));
account.put(SM , UOMCalculation.getM2FromSf(sqFt));
account.put(SF , sqFt);
}
}
//Added for T-131999
public static void removeTeamMembers(Map<Id,Account> accountNewMap, Map<Id,Account> accountOldMap){
map<Id,Id> accIdToGCSOfficerMap = new map<Id,Id>();
list<AccountTeamMember> teamMembersToBeDeleted = new list<AccountTeamMember>();
for(Account acc : accountNewMap.values()){
if((acc.GCS_Account_Officer__c != null &&
acc.GCS_Account_Officer__c != accountOldMap.get(acc.Id).GCS_Account_Officer__c)){
accIdToGCSOfficerMap.put(acc.Id,acc.GCS_Account_Officer__c);
}
}
if(accIdToGCSOfficerMap.size() > 0 ){
for(AccountTeamMember accTeamMember : [Select Id,UserId,AccountId from AccountTeamMember where AccountId IN :
accIdToGCSOfficerMap.keySet()]){
if(accTeamMember.AccountId != null && accIdToGCSOfficerMap.containsKey(accTeamMember.AccountId) &&
accTeamMember.UserId != null && accIdToGCSOfficerMap.get(accTeamMember.AccountId) == accTeamMember.UserId){
teamMembersToBeDeleted.add(accTeamMember);
}
}
}
if(teamMembersToBeDeleted.size() > 0){
delete teamMembersToBeDeleted;
}
}
}
All Answers
I am getting this error while saving class
Error: Compile Error: Method does not exist or incorrect signature: void removeTeamMembers(Map<Id,Account>, Map<Id,SObject>) from the type AccountHelperUtility at line 50 column 34
thank u so much
regarding
Pusapck (https://www.puspack.com/)
Class saved but Test failed
Error
System.StringException: Invalid id: Test
Stack trace
Class.AccountHelperUtilityTest.test: line 27, column 1
GCS_Account_Officer__c is a lookup with user object