@isTest private class AgencyIntelligenceExpireTest { static final String RC_BYOUIN = '病院'; static final String RC_HANBAOITEN = '販売店'; static final String RC_KEIYAKU = '契約'; @isTest static void test_method_one() { // Implement test code RecordType recByoin = [select id from RecordType where IsActive = true and SobjectType= 'Account' and Name=:RC_BYOUIN limit 1]; Account hospital = new Account(Name = 'テスト病院'); hospital.RecordTypeId = recByoin.id; hospital.Site = 'テスト病院部門'; hospital.Alias_Name2__c = 'テスト病院別名'; insert hospital; RecordType recHanbaiten = [select id from RecordType where IsActive = true and SobjectType= 'Account' and Name=:RC_HANBAOITEN limit 1]; Account sellerA = new Account(Name = '販売店'); sellerA.RecordTypeId = recHanbaiten.id; sellerA.Hospital__c = hospital.id; sellerA.Ban_On_Use_Date__c = Date.today().addDays(20); insert sellerA; RecordType recKeiyaku = [select id from RecordType where IsActive = true and SobjectType= 'Account' and Name=:RC_KEIYAKU limit 1]; Account contractA = new Account(Name = '*'); contractA.RecordTypeId = recKeiyaku.id; contractA.Agent_Ref__c = sellerA.id; contractA.ParentId = sellerA.id; insert contractA; System.Test.startTest(); Opportunity opp = new Opportunity( Name='aiueo', StageName='contact', CloseDate=Date.today()); opp.Trade__c = '内貿'; //opp.CurrencyIsoCode = CurrencyIso; opp.Sales_Root__c = '販売店'; opp.StageName = '引合'; opp.Fixed_Check__c = false; opp.owner_not_automatically_update__c = true; //opp.Pricebook2Id = pricebook.id; opp.Purchase_Type__c = '一般引合'; opp.Promise_Class__c = '内貿'; opp.Fund_Basis__c = '政府資金'; opp.AccountId = contractA.id; opp.Hospital__c = contractA.id; opp.Agency1__c = sellerA.id; opp.Wholesale_Price__c = 9000; opp.Opportunity_stage__c = '还没申请预算'; opp.Close_Forecasted_Date__c = Date.today().addDays(50); opp.Special_Opp_lanhai__c = false; insert opp; String CRON_EXP = '0 0 0 3 9 ? 2032'; system.schedule('AgencyIntelligenceExpireTest', CRON_EXP, new AgencyIntelligenceExpireSchedule()); System.Test.StopTest(); } @isTest static void test_method_two() { // Implement test code RecordType recByoin = [select id from RecordType where IsActive = true and SobjectType= 'Account' and Name=:RC_BYOUIN limit 1]; Account hospital = new Account(Name = 'テスト病院'); hospital.RecordTypeId = recByoin.id; hospital.Site = 'テスト病院部門'; hospital.Alias_Name2__c = 'テスト病院別名'; insert hospital; RecordType recHanbaiten = [select id from RecordType where IsActive = true and SobjectType= 'Account' and Name=:RC_HANBAOITEN limit 1]; Account sellerA = new Account(Name = '販売店'); sellerA.RecordTypeId = recHanbaiten.id; sellerA.Hospital__c = hospital.id; sellerA.Business_Paper_Expiration_Date__c = Date.today().addDays(20); insert sellerA; RecordType recKeiyaku = [select id from RecordType where IsActive = true and SobjectType= 'Account' and Name=:RC_KEIYAKU limit 1]; Account contractA = new Account(Name = '*'); contractA.RecordTypeId = recKeiyaku.id; contractA.Agent_Ref__c = sellerA.id; contractA.ParentId = sellerA.id; insert contractA; System.Test.startTest(); Opportunity opp = new Opportunity( Name='aiueo', StageName='contact', CloseDate=Date.today()); opp.Trade__c = '内貿'; //opp.CurrencyIsoCode = CurrencyIso; opp.Sales_Root__c = '販売店'; opp.StageName = '引合'; opp.Fixed_Check__c = false; opp.owner_not_automatically_update__c = true; //opp.Pricebook2Id = pricebook.id; opp.Purchase_Type__c = '一般引合'; opp.Promise_Class__c = '内貿'; opp.Fund_Basis__c = '政府資金'; opp.AccountId = contractA.id; opp.Hospital__c = contractA.id; opp.Agency1__c = sellerA.id; opp.Wholesale_Price__c = 9000; opp.Opportunity_stage__c = '还没申请预算'; opp.Close_Forecasted_Date__c = Date.today().addDays(50); opp.Special_Opp_lanhai__c = false; insert opp; String CRON_EXP = '0 0 0 3 9 ? 2032'; system.schedule('AgencyIntelligenceExpireTest', CRON_EXP, new AgencyIntelligenceExpireSchedule()); System.Test.StopTest(); } @isTest static void test_method_three() { // Implement test code RecordType recByoin = [select id from RecordType where IsActive = true and SobjectType= 'Account' and Name=:RC_BYOUIN limit 1]; Account hospital = new Account(Name = 'テスト病院'); hospital.RecordTypeId = recByoin.id; hospital.Site = 'テスト病院部門'; hospital.Alias_Name2__c = 'テスト病院別名'; insert hospital; RecordType recHanbaiten = [select id from RecordType where IsActive = true and SobjectType= 'Account' and Name=:RC_HANBAOITEN limit 1]; Account sellerA = new Account(Name = '販売店'); sellerA.RecordTypeId = recHanbaiten.id; sellerA.Hospital__c = hospital.id; sellerA.Tax_Practice_Expiration_Date__c = Date.today().addDays(20); insert sellerA; RecordType recKeiyaku = [select id from RecordType where IsActive = true and SobjectType= 'Account' and Name=:RC_KEIYAKU limit 1]; Account contractA = new Account(Name = '*'); contractA.RecordTypeId = recKeiyaku.id; contractA.Agent_Ref__c = sellerA.id; contractA.ParentId = sellerA.id; insert contractA; System.Test.startTest(); Opportunity opp = new Opportunity( Name='aiueo', StageName='contact', CloseDate=Date.today()); opp.Trade__c = '内貿'; //opp.CurrencyIsoCode = CurrencyIso; opp.Sales_Root__c = '販売店'; opp.StageName = '引合'; opp.Fixed_Check__c = false; opp.owner_not_automatically_update__c = true; //opp.Pricebook2Id = pricebook.id; opp.Purchase_Type__c = '一般引合'; opp.Promise_Class__c = '内貿'; opp.Fund_Basis__c = '政府資金'; opp.AccountId = contractA.id; opp.Hospital__c = contractA.id; opp.Agency1__c = sellerA.id; opp.Wholesale_Price__c = 9000; opp.Opportunity_stage__c = '还没申请预算'; opp.Close_Forecasted_Date__c = Date.today().addDays(50); opp.Special_Opp_lanhai__c = false; insert opp; String CRON_EXP = '0 0 0 3 9 ? 2032'; system.schedule('AgencyIntelligenceExpireTest', CRON_EXP, new AgencyIntelligenceExpireSchedule()); System.Test.StopTest(); } @isTest static void test_method_four() { // Implement test code RecordType recByoin = [select id from RecordType where IsActive = true and SobjectType= 'Account' and Name=:RC_BYOUIN limit 1]; Account hospital = new Account(Name = 'テスト病院'); hospital.RecordTypeId = recByoin.id; hospital.Site = 'テスト病院部門'; hospital.Alias_Name2__c = 'テスト病院別名'; insert hospital; RecordType recHanbaiten = [select id from RecordType where IsActive = true and SobjectType= 'Account' and Name=:RC_HANBAOITEN limit 1]; Account sellerA = new Account(Name = '販売店'); sellerA.RecordTypeId = recHanbaiten.id; sellerA.Hospital__c = hospital.id; sellerA.Medical_Equipment_Expiration_Date__c = Date.today().addDays(20); insert sellerA; RecordType recKeiyaku = [select id from RecordType where IsActive = true and SobjectType= 'Account' and Name=:RC_KEIYAKU limit 1]; Account contractA = new Account(Name = '*'); contractA.RecordTypeId = recKeiyaku.id; contractA.Agent_Ref__c = sellerA.id; contractA.ParentId = sellerA.id; insert contractA; System.Test.startTest(); Opportunity opp = new Opportunity( Name='aiueo', StageName='contact', CloseDate=Date.today()); opp.Trade__c = '内貿'; //opp.CurrencyIsoCode = CurrencyIso; opp.Sales_Root__c = '販売店'; opp.StageName = '引合'; opp.Fixed_Check__c = false; opp.owner_not_automatically_update__c = true; //opp.Pricebook2Id = pricebook.id; opp.Purchase_Type__c = '一般引合'; opp.Promise_Class__c = '内貿'; opp.Fund_Basis__c = '政府資金'; opp.AccountId = contractA.id; opp.Hospital__c = contractA.id; opp.Agency1__c = sellerA.id; opp.Wholesale_Price__c = 9000; opp.Opportunity_stage__c = '还没申请预算'; opp.Close_Forecasted_Date__c = Date.today().addDays(50); opp.Special_Opp_lanhai__c = false; insert opp; String CRON_EXP = '0 0 0 3 9 ? 2032'; system.schedule('AgencyIntelligenceExpireTest', CRON_EXP, new AgencyIntelligenceExpireSchedule()); System.Test.StopTest(); } }