@isTest private class AgencyOpportunityManageCotrollerTest { public static Account account1 = new Account(); public static Account account2 = new Account(); public static Contact contact1 = new Contact(); public static Contact contact2 = new Contact(); public static User user = new User(); public static Agency_Hospital_Link__c agency_hospital_link = new Agency_Hospital_Link__c(); public static Agency_Opportunity__c agency_opportunity = new Agency_Opportunity__c(); static testMethod void testMethod1() { Oly_TriggerHandler.bypass('AgencyReportHeaderHandler'); Oly_TriggerHandler.bypass('AgencyHospitalHandler'); StaticParameter.EscapeAccountTrigger = true; StaticParameter.EscapeNFM007Trigger = true; StaticParameter.EscapeOpportunityBefUpdTrigger = true; StaticParameter.EscapeOpportunityHpDeptUpdTrigger = true; StaticParameter.EscapeSyncOpportunityTrigger = true; StaticParameter.EventOpportunityPileUpExeFlg = true; StaticParameter.EscapeNFM001AgencyContractTrigger = true; StaticParameter.EscapeNFM001AgencyContractTrigger2 = true; StaticParameter.EscapeLeadTrigger = true; StaticParameter.EscapeOpportunityownerUpdate = true; ControllerUtil.EscapeNFM001Trigger = true; ControllerUtil.EscapeMaintenanceContractAfterUpdateTrigger = true; StaticParameter.EscapeNFM001Trigger = true; StaticParameter.EscapeMaintenanceContractAfterUpdateTrigger = true; // 取引先 account1.Name = 'test1医院'; account1.RecordTypeId = '01210000000QemG'; insert account1; List acclist=[select RecordTypeId,Name from Account ]; account2.Name = 'test1经销商'; account2.RecordTypeId = '01210000000Qem1'; insert account2; List acc2list=[select RecordTypeId,Name from Account ]; // 取引先責任者 contact1.AccountId = account1.Id; contact1.FirstName = '責任者'; contact1.LastName = 'test1医院'; insert contact1; List contactlist=[select Id,FirstName from Contact ]; contact2.AccountId = account2.Id; contact2.FirstName = '責任者'; contact2.LastName = 'test1经销商'; insert contact2; List contact2list=[select Id,FirstName from Contact ]; // ユーザー Profile p = [select Id from Profile where Name = '901_经销商活动系统']; user.ProfileId = p.Id; user.FirstName = 'ユーザー'; user.LastName = 'テスト'; user.Email = 'test_user@example.com'; user.emailencodingkey='UTF-8'; user.languagelocalekey='zh_CN'; user.localesidkey='ja_JP'; user.timezonesidkey='Asia/Shanghai'; user.Username = 'test_user@example.com' + System.now().millisecond(); user.Alias = 'テユ'; user.CommunityNickname = 'tu' + System.now().millisecond(); user.ContactId = contact2.Id; insert user; List users = [select Id,Name,LastName, FirstName from User where LastName='テスト']; agency_hospital_link.Name = 'test1代理店医院'; agency_hospital_link.Hospital__c = account1.Id; agency_hospital_link.Agency__c = account2.Id; agency_hospital_link.OwnerId = user.Id; agency_hospital_link.Agency_Campaign_Obj__c = true; insert agency_hospital_link; List agencylist=[select Id,Name from Agency_Hospital_Link__c where Id =: agency_hospital_link.Id]; Id rtId = Schema.SObjectType.Agency_Opportunity__c.getRecordTypeInfosByDeveloperName().get('Opportunity').getRecordTypeId(); agency_opportunity.Agency_Person__c = contactlist[0].id; agency_opportunity.RecordTypeId = rtId; agency_opportunity.Name = 'TEST AgencyOpp'; agency_opportunity.Hospital_Target__c = account1.Id; agency_opportunity.Agency__c = account2.Id; agency_opportunity.Agency_Hospital__c = agency_hospital_link.Id; agency_opportunity.StageName__c = '还没申请预算'; agency_opportunity.OwnerId = user.Id; agency_opportunity.NewOpportunity_Agency_Apply_Status__c = '批准'; agency_opportunity.Department_Cateogy__c = 'ET'; agency_opportunity.Sales_Manager__c = user.Id; insert agency_opportunity; List opportunitylist=[select Id,Name from Agency_Opportunity__c]; User user2 = new User(); Profile p2 = [select Id from Profile where Name = '2S1_销售医院担当']; user2.ProfileId = p2.Id; user2.FirstName = 'ユーザー2'; user2.LastName = 'テスト2'; user2.Email = 'test_user@example.com'; user2.emailencodingkey='UTF-8'; user2.languagelocalekey='zh_CN'; user2.localesidkey='ja_JP'; user2.timezonesidkey='Asia/Shanghai'; user2.Username = 'test_user@example.com' + System.now().millisecond(); user2.Alias = 'テユ2'; user2.CommunityNickname = 'tu' + System.now().millisecond(); insert user2; system.runAs(user2) { AgencyOpportunityManageCotroller.getCurrentAgencyOpportunity(); } } }