• Nancy Gresham
  • NEWBIE
  • 20 Points
  • Member since 2016
  • CRM and Systems Admin
  • e-MDs

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 3
    Replies
Hi All! 
I'm having trouble writing a test for this trigger.  I can get 65% coverage, but not more.  I'm new to this, so I'm sure there is something small I'm missing somewhere.  Any help would be awesome! Thanks!
trigger CaseResolutionTrigger on Case (after update) 
{
    Set<String> caseIdSet = new Set<String>(); 
    if(CaseResolutionTriggerHandler.isFirstTime)
    {
        CaseResolutionTriggerHandler.isFirstTime = false;
        
	Set<ID> RTIds = new Set<ID>();  //set of Record Type IDs to match
        
        List<CaseComment> CommentList = new List<CaseComment>();
        List<Time_Entry__c> TEList = new List<Time_Entry__c>();
     
        for(RecordType rt : [select id from Recordtype where SobjectType='Case' and ((Name like 'e-MDs%') or (Name like 'Richmond%'))]){
  		  RTIds.add(rt.id);
			}   
    for(Case ca : Trigger.New)    {
    
      //Only when Resolution is changed and only for specified Record Types - Insert Comment and Time Entry     
	if(RTIds.contains(ca.Recordtypeid) && ca.Resolution__c != '' && ca.Resolution__c != Trigger.oldmap.get(ca.id).Resolution__c){
        CaseComment com = new CaseComment();
        com.ParentId = ca.id;
        com.CommentBody= 'RESOLUTION:  '+ '\n' + ca.Resolution__c;
        CommentList.add(com);
        
        Time_Entry__c te = new Time_Entry__c();
        te.Case__c  = ca.id;
        te.Minutes_Spent__c = ca.Minutes_SMB__c;
        TEList.add(te);
         
}
        //clear the number passed from the case to the Time Entry
      Case c = [Select id, Minutes_SMB__c from Case where id = :ca.id];
        c.Minutes_SMB__c = NULL;
        update c;
                            }

		Insert CommentList;
        Insert TEList;
        

}
}

 

Hi guys! I've written my first trigger, which works in my sandbox, but I can't successfully write a test for it.  The field that it filters on is a read only formula field.  Any help would be greatly appreciated!
Thanks much!

trigger accountRankings on Account(after insert, after update, after delete){

for(Account acc : trigger.new)
{
//checking if the value is changed
if(acc.VAROrderPointsYTD__c != Null && (trigger.isInsert || (trigger.newMap.get(acc.id).VAROrderPointsYTD__c != trigger.oldMap.get(acc.id).VAROrderPointsYTD__c)))
{
break;
}
else return;
}

//rank top 100 accounts for more accounts change the row limit
List<Account> accounts = [Select VAROrderPointsYTD__c, Point_Ranking__c from Account Where RecordType.Name = 'Richmond VAR' ORDER BY VAROrderPointsYTD__c DESC limit 100];

Integer rank = 1;
for (Account account : accounts)
{
account.Point_Ranking__c = rank;
rank++;
}
update accounts;
}
 

 

Hi All! 
I'm having trouble writing a test for this trigger.  I can get 65% coverage, but not more.  I'm new to this, so I'm sure there is something small I'm missing somewhere.  Any help would be awesome! Thanks!
trigger CaseResolutionTrigger on Case (after update) 
{
    Set<String> caseIdSet = new Set<String>(); 
    if(CaseResolutionTriggerHandler.isFirstTime)
    {
        CaseResolutionTriggerHandler.isFirstTime = false;
        
	Set<ID> RTIds = new Set<ID>();  //set of Record Type IDs to match
        
        List<CaseComment> CommentList = new List<CaseComment>();
        List<Time_Entry__c> TEList = new List<Time_Entry__c>();
     
        for(RecordType rt : [select id from Recordtype where SobjectType='Case' and ((Name like 'e-MDs%') or (Name like 'Richmond%'))]){
  		  RTIds.add(rt.id);
			}   
    for(Case ca : Trigger.New)    {
    
      //Only when Resolution is changed and only for specified Record Types - Insert Comment and Time Entry     
	if(RTIds.contains(ca.Recordtypeid) && ca.Resolution__c != '' && ca.Resolution__c != Trigger.oldmap.get(ca.id).Resolution__c){
        CaseComment com = new CaseComment();
        com.ParentId = ca.id;
        com.CommentBody= 'RESOLUTION:  '+ '\n' + ca.Resolution__c;
        CommentList.add(com);
        
        Time_Entry__c te = new Time_Entry__c();
        te.Case__c  = ca.id;
        te.Minutes_Spent__c = ca.Minutes_SMB__c;
        TEList.add(te);
         
}
        //clear the number passed from the case to the Time Entry
      Case c = [Select id, Minutes_SMB__c from Case where id = :ca.id];
        c.Minutes_SMB__c = NULL;
        update c;
                            }

		Insert CommentList;
        Insert TEList;
        

}
}

 

Hi guys! I've written my first trigger, which works in my sandbox, but I can't successfully write a test for it.  The field that it filters on is a read only formula field.  Any help would be greatly appreciated!
Thanks much!

trigger accountRankings on Account(after insert, after update, after delete){

for(Account acc : trigger.new)
{
//checking if the value is changed
if(acc.VAROrderPointsYTD__c != Null && (trigger.isInsert || (trigger.newMap.get(acc.id).VAROrderPointsYTD__c != trigger.oldMap.get(acc.id).VAROrderPointsYTD__c)))
{
break;
}
else return;
}

//rank top 100 accounts for more accounts change the row limit
List<Account> accounts = [Select VAROrderPointsYTD__c, Point_Ranking__c from Account Where RecordType.Name = 'Richmond VAR' ORDER BY VAROrderPointsYTD__c DESC limit 100];

Integer rank = 1;
for (Account account : accounts)
{
account.Point_Ranking__c = rank;
rank++;
}
update accounts;
}