I have a trigger that is supposed to see if a field is empty and, if it is empty, it is supposed to check if there is an Account Team Member with a certain role. If that is true then it is supposed to delete that team member. I can only get 60% code coverage on it and I've been wondering why. I am new to writing code. My trigger and test class are below.
TRIGGER
trigger DeleteATM on Account(after insert, after update) {
List<Id> lstId = new List<Id>();
for(Account acc: Trigger.new){
if (acc.Customer_Success_Manager__c== null) {
List<AccountTeamMember> atm = [Select UserId from AccountTeamMember where TeamMemberRole =: 'Customer Success Manager' AND AccountID=:acc.id AND UserID!=:acc.Customer_Success_Manager__c];
delete atm;
}
}
}
TEST CLASS
@isTest
Public class RemoveCSMTest {
Static testMethod void insertNewAccount() {
Account Cre = new Account();
Cre.Market__c = 'Houston';Cre.Business_Unit__c = '334';
Cre.Name = 'Test CSM2';
Cre.Customer_Success_Manager__c = '005A0000000SAC0';
Insert cre;
List<Account> a = [SELECT Id, Name, Customer_Success_Manager__c FROM Account WHERE Name = 'TestCSM2'];
for (Account accs : a){
accs.Customer_Success_Manager__c=NULL;
Update accs;
}
}
}
{
and}
lines. Try to put the{
and}
in the end of a line with some code. – SF_user Nov 6 '14 at 14:21AccountTeamMember
record so that the SOQL query in your trigger returns at least one record. – BarCotter Nov 6 '14 at 14:56