+ Start a Discussion
Glen.ax1034Glen.ax1034 

Case RecordType --- if statement coming out false, why?

The code that is coming out false reads: if(maprtID_rtName.get(escalatedcase.id) == 'NationalClientService') {
for some reason, it comes out false... not sure why, but i tried to debug it by pritning out the value for maprtID_rtName.get(escalatedcase.id)) and it errors saying that it is printing nulls.
here's my record type: 
Record Type Label	National Client Service	Active	
Support Process	National Client Service	 	 
Record Type Name	NationalClientService

 

CODE BELOW:
trigger EscalateCase on Case (before update) {
  List<RecordType> rTypes = [select id,name from RecordType where SobjectType='Case'];    //pull recordtype Id's and record type names from recordtypes where the sobject is contract
 	
  MAP<Id , String> maprtID_rtName = new MAP<ID , String>();  //map record type ID's to record type names.
  for(RecordType rTypeObj :  rTypes)
  {
  	maprtID_rtName.put(rTypeObj.id , rTypeObj.Name); //for all recordtypes... log id's and record type names.
  }
  
  List<RecordType> rTypesCases = [select name,id from RecordType where SobjectType='Case'];    //pull recordtype Id's and record type names from recordtypes where the sobject is contract
  
  MAP<String, ID> maprtName_rtIDCases = new MAP<String, ID>();  //map record type ID's to record type names.
  for(RecordType rTypeObj :  rTypesCases)
  {
  	maprtName_rtIDCases.put(rTypeObj.Name, rTypeObj.id); //for all recordtypes... log id's and record type names.
  }


List<Case> Cases = new List<Case>();
for (Case escalatedcase:Trigger.new){

//trying to close the parent case while children are still open	
if (escalatedcase.Status=='Closed') { //trying to close the parent case while children are still open
	integer close = [Select count() from Case where ParentId = :escalatedcase.id and isClosed != true];
	if (close > 0) {
		escalatedcase.addError('There are still Child Cases Open - Please close and try again!');
	}
}
//END trying to close the parent case while children are still open


	if(maprtID_rtName.get(escalatedcase.id) == 'NationalClientService') { // This is the IF statement that is failing.
		if (escalatedcase.Escalate_to__c == 'Tier 2 - Internal Support') {
			if(escalatedcase.Tier_2_Escalation_Level__c == 'Billing Resolution') {
				if (escalatedcase.IsEscalated==false) {
					if(escalatedcase.ParentId == null) {
						Case CaseAdd = escalatedcase.clone(false, true);
						CaseAdd.RecordTypeId = maprtName_rtIDCases.get('Billing Resolution');
						CaseAdd.ParentId = escalatedcase.id;
						Cases.add(CaseAdd);
						escalatedcase.Status = 'Escalated to Tier 2';
						escalatedcase.IsEscalated = true;
					} else {
						if(escalatedcase.Status == 'Closed') {
							Case CaseAdd = new Case(Id = escalatedcase.ParentId);
							CaseAdd.Status = 'Completed';
							CaseAdd.IsEscalated = false;
							Cases.add(CaseAdd);
						}
						
					}
				}
			}
		}
	} else {
		escalatedcase.addError('test');
		escalatedcase.addError(maprtID_rtName.get(escalatedcase.id)); ///It's throwing the error down here... because the if statement from above is false
	}



}

upsert Cases;

}

 

Record Type LabelNational Client ServiceActiveChecked
Support ProcessNational Client Service  
Record Type NameNationalClientService
Best Answer chosen by Admin (Salesforce Developers) 
WizradWizrad

Glen,

 

The way you are setting up the map it maps the record type id to the name of the record type.  Then you try to use the id of a case as a key to the map.  Instead of doing 

 

maprtID_rtName.get(escalatedcase.id)

 Try

 

maprtID_rtName.get(escalatedcase.RecordTypeId)