@isTest
|
private class CaseHpDeptUpdTriggerTest {
|
|
static testMethod void myUnitTest() {
|
// レコードタイプ取得
|
RecordType hospitalRec = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
|
RecordType sectionRec = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 消化科'];
|
RecordType departmentRec = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 消化科'];
|
|
// 病院作成
|
Account hospital = new Account();
|
hospital.RecordTypeId = hospitalRec.Id;
|
hospital.Name = 'TestHospital';
|
insert hospital;
|
|
// 病院を作ると戦略科室は、トリガーによって作られている
|
Account section = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Parent.Id = :hospital.Id and RecordTypeId = :sectionRec.Id limit 1];
|
|
// 診療科1を作成
|
Account depart1 = new Account();
|
depart1.RecordTypeId = departmentRec.Id;
|
depart1.Name = '*';
|
depart1.Department_Name__c = 'TestDepart';
|
depart1.ParentId = section.Id;
|
depart1.Department_Class__c = section.Id;
|
depart1.Hospital__c = hospital.Id;
|
depart1.AgentCode_Ext__c = '9999997';
|
insert depart1;
|
|
Contact con = new Contact();
|
con.FirstName ='ZZ';
|
con.LastName = 'test contact';
|
con.Email = 'daiske@oly.com.tesst';
|
con.accountId = depart1.id;
|
insert con;
|
|
Case cic = new Case();
|
cic.ContactId = con.Id;
|
insert cic;
|
|
cic.ContactId = null;
|
update cic;
|
}
|
}
|