Skip to main content
hema priya (.qr) perguntou em #Apex

trigger ParentChildcase on Case (before update) {

String QueueDeveloperName='Welcome_Call_Queue';

Group CaseQueue=[select id,name,DeveloperName from group where type='Queue' AND developername='Welcome_Call_Queue'];

system.debug('*****CaseQueue:'+CaseQueue);

List<Case> listCase = [select Id,parentId,status from case where parentId != null ];

////List<Queues> listqueue = [select Id from Queues where name = 'Welcome_Call_Queue'];

system.debug('listCase'+listCase);

map<Id,list<Case>> mapCase = new map<Id,list<Case>>();

for(Case objCase : listCase){

if(objCase.status != 'Closed'){

List<Case> listCasemap = new List<Case>();

if(mapCase.containskey(objCase.parentId))

listCasemap = mapCase.get(objCase.parentId);

listCasemap.add(objCase);

mapCase.put(objCase.parentId,listCasemap);

}

}

system.debug('mapCase'+mapCase);

for(case caseObj:Trigger.New){

if(caseObj.parentId == null && caseObj.Status == 'Closed'){

if(mapCase.containskey(caseObj.Id)){

List<Case> listCasemap = mapCase.get(caseObj.Id);

if(listCasemap.size() != 0){

caseObj.addError('OPEN CHILD CASES ARE PRESENT.PLEASE CLOSE THESE CASES');

}

}

}

system.debug('caseObj.Owner.Name'+caseObj.Owner.Name);

if(caseObj.OwnerID == CaseQueue.id && caseObj.Status == 'Closed'){

caseObj.addError('PLEASE CHANGE THE CASE OWNER TO CLOSE THE CASE');

}

}

}

TESTCASE:

@istest

Public class TM_ParentChildcase

{

Public static testmethod void ParentChildcase()

{

Id caseRID = StaticUtil.getRecordTypeId('case','Call Center Case');

Account a = new Account();

a.Name = 'Test Individual Account123';

a.First_Name__c= 'Test Account123';

a.Last_Name__c= 'Test Account123';

a.BillingStreet = 'test';

a.BillingCity = 'Test';

a.Dealer_Code__c = 'A1234';

a.BillingState = 'Test';

a.BillingPostalCode = '34566';

a.BillingCountry = 'AUS';

a.Email__c = 'test@test.com';

a.Mobile_Phone__c ='12345678901';

insert a;

Contact con = new Contact();

con.FirstName = 'FirstName1';

con.LastName = 'LastName1';

con.AccountId = a.Id;

// con.RecordTypeId = DealerContactRID;

con.Email = 'test@test.com';

con.MobilePhone ='12345678901';

insert con;

case c = new case();

c.Contacts__c = con.id;

c.type = 'inquirytest';

c.Origin ='phonetest';

insert c;

c.Case_Description__c ='closed';

c.Status ='new';

update c;

}

}

 
2 respostas
  1. 1 de abr. de 2015, 08:54
    Hi Hema, 

    Please try the above code and let me know if that helps you to resolve your coverage issue..

    Thanks