@isTest private class AgencyQuolifiedExpireBatchTest { static testMethod void testMethod1() { List rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院']; // if (rectCo.size() == 0) { // return; // } List rectSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 呼吸科']; // if (rectSct.size() == 0) { // return; // } List rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 消化科']; // if (rectDpt.size() == 0) { // return; // } List rectAgency = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店']; // if (rectAgency.size() == 0) { // return; // } // テストデータ Account company = new Account(); company.RecordTypeId = rectCo[0].Id; company.Name = 'NFM206TestCompany'; insert company; Account section = new Account(); section.RecordTypeId = rectSct[0].Id; section.Name = '*'; section.Department_Class_Label__c = '消化科'; section.ParentId = company.Id; section.Hospital_Department_Class__c = company.Id; insert section; Account depart = new Account(); depart.RecordTypeId = rectDpt[0].Id; depart.Name = '*'; depart.Department_Name__c = 'NFM206TestDepart'; depart.ParentId = section.Id; depart.Department_Class__c = section.Id; depart.Hospital__c = company.Id; insert depart; Date today = Date.today(); Date lastDate1 = Date.today().addMonths(1); Date lastDate2 = Date.today().addMonths(2); Date lastDate3 = Date.today().addMonths(3); Account account2 = new Account(); account2.Name = 'test1经销商'; account2.RecordTypeId = rectAgency[0].id; insert account2; Opportunity opp = new Opportunity(); opp.AccountId = depart.Id; opp.Department_Class__c = section.Id; opp.Hospital__c = company.Id; opp.SAP_Send_OK__c = false; opp.Name = 'GZ-SP-NFM009_0'; opp.agency1__c = account2.Id; opp.Trade__c = '内貿'; opp.StageName = '出荷'; opp.CloseDate = lastDate1; opp.Close_Forecasted_Date__c = lastDate1; opp.Stock_apply_status__c = '申请中'; insert opp; System.Test.StartTest(); Statu_Achievements__c sta1 = new Statu_Achievements__c(); sta1.Statu_Achievements_Ext__c = 'opp1:SoNo1'; sta1.Name = 'SoNo1'; sta1.Opportunity__c = opp.Id; sta1.ReturnFlag__c = false; sta1.OverviewStatus__c = 'OverviewStatus__c'; sta1.ContractNO__c = 'ContractNO1'; sta1.ContractReceivedDate__c = null; sta1.FirstApproveDate__c = null; sta1.LastApproveDate__c = null; sta1.SoLatestDeliveryDate__c = null; sta1.DeliveryDate__c = null; sta1.InstallDate__c = null; sta1.Collection_Day_Invoice__c = System.today(); sta1.CurrencyIsoCode = opp.CurrencyIsoCode; sta1.ContractAmount__c = 10000; sta1.PaymentAmount__c = 0; sta1.PaymentRate__c = '0'; sta1.DeliveryStatus__c = 'DeliveryStatus__c'; sta1.AssignmentStatus__c = 'AssignmentStatus__c'; sta1.PaymentStatus__c = 'PaymentStatus__c'; sta1.InstallStatus__c = 'InstallStatus__c'; sta1.AuthorizationNo__c = 'AuthorizationNo__c'; sta1.ContractApplicationNo__c = 'ContractApplicationNo__c'; sta1.PaymentTerms__c = 'PaymentTerms__c'; sta1.UnshippedAmount__c = 1000; sta1.SalesChannel__c = 'SalesChannel__c'; sta1.SoLatestDeliveryDate__c = Date.today().addDays(5); insert sta1; // Id a = sta1.Id; // List statuAchievelist = [select id,UnshippedAmount_F__c,Status_2_Formula__c from Statu_Achievements__c where Id = :a]; // System.debug(Integer.valueOf(statuAchievelist[0].UnshippedAmount_F__c+statuAchievelist[0].Status_2_Formula__c)); // Id execBTId = null; // execBTId = Database.executeBatch(new AgencyQuolifiedExpireBatch(),20); Database.executeBatch(new AgencyQuolifiedExpireBatch(),20); System.Test.StopTest(); } }