@isTest private class AllAssetControllerTest { static Product2 prd1; static Product2 prd2; static Account acc; static Account dealer; static Contact core; static User testUser; static loaner_Set__c loanerSet; //转借元代理商 static Account leaddealer; static testMethod void setupTestData() { List dealerIE = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Dealer']; if (dealerIE.size() == 0) { return; } List olyCompany = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'OlympusCompany']; if (olyCompany.size() == 0) { return; } List loa_individual = [select Id from RecordType where IsActive = true and SobjectType = 'Asset' and Name = '样机_个体管理']; if (loa_individual.size() == 0) { return; } List loa_number = [select Id from RecordType where IsActive = true and SobjectType = 'Asset' and Name = '样机_数量管理']; if (loa_number.size() == 0) { return; } //代理商用户 List rectDealer = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Dealer']; Profile prof = [select Id from Profile where Name ='SSBG DEALER IE']; dealer = new Account(); dealer.Name = 'test dealer'; dealer.RecordTypeId = rectDealer[0].Id; dealer.ProductSegment__c = 'BS'; dealer.PostCode__c='000000'; insert dealer; core = new Contact(email='jplumber@salesforce.com', firstname='Joe',lastname='Plumber',accountid=dealer.id); insert core; testUser = New User(ContactId = core.id,Alias = 'newUser',Email='newuser@testorg.com',EmailEncodingKey='UTF-8', LastName='TestUser', LanguageLocaleKey='zh_CN',LocaleSidKey='zh_CN', ProfileId = prof.Id,TimeZoneSidKey='Asia/Shanghai', UserName='testUser01@prectech.com'); insert testUser; //样机客户 acc = new Account(); acc.Name = 'test dealer'; acc.RecordTypeId = olyCompany[0].Id; acc.ProductSegment__c = 'BS'; acc.PostCode__c='000000'; insert acc; loanerSet = new loaner_Set__c(); loanerSet.Equipment_Type__c = 'BS'; loanerSet.Set_No__c = 'IETEST0001'; loanerSet.Name = 'IETEST0001'; insert loanerSet; // 产品 prd1 = new Product2(); prd1.Product_ECCode__c = 'testSBG001'; prd1.ProductCode = 'testSBG001'; prd1.Name = 'testSBG001'; prd1.IsActive = true; prd2 = new Product2(); prd2.Product_ECCode__c = 'testSBG002'; prd2.ProductCode = 'testSBG002'; prd2.Name = 'testSBG002'; prd2.IsActive = true; insert new Product2[] {prd1, prd2}; // 保有设备 (数量管理) Asset asset = new Asset(); asset.RecordTypeId = loa_number[0].Id; asset.SerialNumber = 'asset'; asset.Name = 'asset'; asset.AccountId = acc.Id; asset.Product2Id = prd2.Id; asset.Quantity = 1; asset.Status = '在库'; asset.Equipment_Type__c = 'BS'; asset.loaner_place__c = '广州办'; asset.total_number__c = 20; asset.Remarks2__c = 'asset'; // 保有设备 (个体管理) Asset assetC1 = new Asset(); assetC1.RecordTypeId = loa_individual[0].Id; assetC1.SerialNumber = 'assetC1'; assetC1.Name = 'assetC1'; assetC1.AccountId = acc.Id; assetC1.Product2Id = prd1.Id; assetC1.Quantity = 1; assetC1.Status = '在库'; assetC1.Equipment_Type__c = 'BS'; assetC1.loaner_place__c = '北京酒仙桥'; assetC1.Remarks2__c = 'assetC1'; // 保有设备 (个体管理) Asset assetC2 = new Asset(); assetC2.RecordTypeId = loa_individual[0].Id; assetC2.SerialNumber = 'assetC2'; assetC2.Name = 'assetC2'; assetC2.AccountId = acc.Id; assetC2.Product2Id = prd1.Id; assetC2.Quantity = 1; assetC2.Status = '在库'; assetC2.Equipment_Type__c = 'BS'; assetC2.loaner_place__c = '北京酒仙桥'; insert new Asset[] {asset,assetC1}; Loaner_Set_Detail__c lSD1 = new Loaner_Set_Detail__c(); lSD1.Loaner_Set__c = loanerSet.Id; lSD1.Asset__c = asset.Id; Loaner_Set_Detail__c lSD2 = new Loaner_Set_Detail__c(); lSD2.Loaner_Set__c = loanerSet.Id; lSD2.Asset__c = assetC1.Id; insert new Loaner_Set_Detail__c[] {lSD1,lSD2}; AllAssetController assetTest = new AllAssetController(); assetTest.init(); assetTest.assName = '1'; assetTest.assECcode = '1'; assetTest.rec.loaner_place__c = '1'; assetTest.rec.Status = '1'; assetTest.rec.SerialNumber = '1'; assetTest.rec.Internal_Asset_number__c = '1'; assetTest.searchLoanerApp(); assetTest.setId = loanerSet.id; assetTest.getLoanerSetdet(); Integer i = assetTest.loanerSetNo; i = assetTest.pageRecordNo; } }