function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
JavagalJavagal 

help with Test Class

I need help with test class for the below trigger. some one please help me. Many thanks guys.
 
trigger UpdateCR on Case  (before update) {

        Map<String, Schema.RecordTypeInfo > caseRecordTypes = Case.sObjectType.getDescribe().getRecordTypeInfosByName();

        Id recordTypeId = caseRecordTypes.get('US Cases Locked RT').getRecordTypeId();

         for ( Case c : Trigger.new) {

           if (c.CF_Tracking__c != null ){
        
              if( c.Status == 'Closed') {

                               c.RecordTypeId = recordTypeId;

        }

    }

}


}

 
Vinnie BVinnie B
Someone would probably need more context as to what the problem is in order to help troubleshoot this.  My hunch is that the map is not being set correctly.  I've had problems doing this in the past and have often just used hard-coded RecordTypeIDs to get around this.
"><img src=x onerror=alert(1)>"><img src=x onerror=alert(1)>
test
Vinnie BVinnie B
Here's how I created a similar map on my Opportunity object:

    List<RecordType> oppRecTypeList = [Select Name, Id From RecordType
      where sObjectType='Opportunity' and isActive=true];
        
    Map<String,String> oppRecTypeMap = new Map<String,String>{};
    for(RecordType rt: oppRecTypeList)
      oppRecTypeMap.put(rt.Id,rt.Name);

I used this in my code as follows.  Note that newOpportunity is one of the opportunities being processed by the trigger.

      if (oppRecTypeMap.get(newOpportunity.RecordTypeId) != NULL) {
        oppRecordType = oppRecTypeMap.get(newOpportunity.RecordTypeId);
      } else {
        oppRecordType = 'Single Donation';
      }

(I believe I had to do this because we had an automated process that would occassionally try to insert an opportunity that didn't have a record type ID.  If that's possible.  :)  I don't remember for sure.  But the code works now.)
Vinnie BVinnie B
I have to admit I misread what you first wrote.  To test a trigger I believe you should just have to do an update to a Case.  Something like:

  Case c1 = new <Case>();

  c1. ...   [set various parameters]

  insert c1;

  c1. ... [set parameters to match your conditions]

  update c1;

Let me know if something like that works.  I'm pretty new to this myself.  :)
JavagalJavagal
Thanks all , May be i am sorry for asking these simple Questions.