@isTest private class OpportunityTriggerTest { @isTest static void test_method_one() { 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; } StaticParameter.EscapeOpportunityBefUpdTrigger = true; StaticParameter.EscapeSyncOpportunityTrigger = true; StaticParameter.EscapeNFM007Trigger = true; StaticParameter.EscapeOpportunityHpDeptUpdTrigger = true; StaticParameter.EscapeSyncOpportunityTrigger = true; StaticParameter.EscapeOppandStaTrigger = true; StaticParameter.EscapeAccountTrigger = true; System.runAs(new User(Id = Userinfo.getUserId())) { // テストデータ Account company = new Account(); company.RecordTypeId = rectCo[0].Id; company.Name = 'NFM007TestCompany'; upsert 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; upsert section; Account depart = new Account(); depart.RecordTypeId = rectDpt[0].Id; depart.Name = '*'; depart.Department_Name__c = 'NFM007TestDepart'; depart.ParentId = section.Id; depart.Department_Class__c = section.Id; depart.Hospital__c = company.Id; upsert depart; // 插入询价 String rectAgency = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Agency').getRecordTypeId(); // 販売店 Account sellerA = new Account(RecordTypeId = rectAgency, Name = 'Agency'); sellerA.Is_Active__c = '有効'; insert sellerA; Opportunity opp = new Opportunity(); opp.Name = '引合1'; opp.AccountId = depart.Id; opp.Opportunity_Category__c = 'ENT'; opp.Trade__c = '外貿'; opp.StageName = '出荷'; opp.CurrencyIsoCode = 'CNY'; opp.Close_Forecasted_Date__c = date.today().addMonths(1); opp.CloseDate = date.today().addMonths(1); opp.Sales_Root__c = 'OCM直接販売'; opp.Hospital__c = company.id; opp.Department_Class__c = section.id; opp.Stock_apply_status__c = '申请中'; opp.Configuration_Suggestion__c = '无建议'; insert opp; Quote q = new Quote( Name = 'quote', OpportunityId = opp.Id ); insert q; System.Test.startTest(); Opportunity_File__c ofile = new Opportunity_File__c(); ofile.Name = 'test file'; ofile.Opportunity__c = opp.Id; ofile.Is_Locked__c = false; insert ofile; // //opp.Stock_apply_status__c = '批准'; // //opp.Department_Class__c = section1.Id; // opp.OwnerId = Userinfo.getUserId(); // update opp; opp.Estimation_No__c = q.Quote_No__c; opp.Stock_apply_status__c = '批准'; opp.Configuration_Suggestion__c = '有建议'; opp.StageName = '削除'; OpportunityTrigger.isFirst =true; update opp; System.Test.stopTest(); // OpportunityTrigger.intI(); } } /** @isTest static void test_Change_Quote() { 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; } // テストデータ Account company = new Account(); company.RecordTypeId = rectCo[0].Id; company.Name = 'NFM007TestCompany'; upsert 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; upsert section; Account depart = new Account(); depart.RecordTypeId = rectDpt[0].Id; depart.Name = '*'; depart.Department_Name__c = 'NFM007TestDepart'; depart.ParentId = section.Id; depart.Department_Class__c = section.Id; depart.Hospital__c = company.Id; upsert depart; RecordType recByoin = [select id from RecordType where IsActive = true and SobjectType= 'Account' and Name=:'病院' 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=:'販売店' limit 1]; Account sellerA = new Account(Name = '販売店'); sellerA.RecordTypeId = recHanbaiten.id; sellerA.Hospital__c = hospital.id; sellerA.Tax_Practice_No__c = '001'; sellerA.Sales_Shop_Class__c = '特約販売店(区域)'; sellerA.Business_Authorization_No__c = '001'; sellerA.Tax_Practice_Expiration_Date__c = Date.today().addDays(20); sellerA.Business_Paper_Expiration_Date__c = Date.today().addDays(20); sellerA.Medical_Equipment_Expiration_Date__c = Date.today().addDays(20); sellerA.Medical_Equipment_Num__c = '有证'; sellerA.Business_Authorization_No__c = '0001'; sellerA.Business_Paper_Expiration_Date__c = Date.today().addDays(20); sellerA.Delete_Flag__c = false; Oly_TriggerHandler.bypass('AccountTrigger'); Oly_TriggerHandler.bypass('AfterCreateHospitalTrigger'); insert sellerA; // Account sellerB = new Account(Name = '販売店B'); // sellerB.RecordTypeId = recHanbaiten.id; // sellerB.Delete_Flag__c = false; // insert sellerB; Oly_TriggerHandler.bypass('PowerBIBaseHandler'); StaticParameter.EscapeSyncOpportunityTrigger = true; StaticParameter.EscapeNFM007Trigger = true; StaticParameter.EscapeOpportunityHpDeptUpdTrigger = true; Oly_TriggerHandler.bypass('AgencyOppUpdHandler'); StaticParameter.EscapeSyncOpportunityTrigger = true; StaticParameter.EscapeOppandStaTrigger = true; StaticParameter.EscapeAccountTrigger = true; System.Test.startTest(); 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-NFM007_1'; opp.Trade__c = '内貿'; opp.StageName = '引合'; opp.CloseDate = date.newinstance(2025, 11, 30); opp.Stock_apply_status__c = '申请中'; insert opp; Quote q = new Quote( Name = 'quote', OpportunityId = opp.Id, Agency1__c = sellerA.Id, Quote_No__c = 'Quote_No_1' ); insert q; opp.Agency1__c = sellerA.Id; opp.Estimation_No__c = q.Quote_No__c; update opp; // opp.Agency1__c = sellerB.Id; // update opp; System.Test.stopTest(); } */ //2021-05-13 mzy QLM @isTest static void test_Change_Opp() { 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; } // テストデータ Account company = new Account(); company.RecordTypeId = rectCo[0].Id; company.Name = 'NFM007TestCompany'; upsert 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; upsert section; Account depart = new Account(); depart.RecordTypeId = rectDpt[0].Id; depart.Name = '*'; depart.Department_Name__c = 'NFM007TestDepart'; depart.ParentId = section.Id; depart.Department_Class__c = section.Id; depart.Hospital__c = company.Id; upsert depart; //販売店 RecordType recHanbaiten = [select id from RecordType where IsActive = true and SobjectType= 'Account' and Name='販売店' limit 1]; Account sellerA = new Account(Name = '販売店A'); sellerA.RecordTypeId = recHanbaiten.id; sellerA.Delete_Flag__c = false; insert sellerA; Account sellerB = new Account(Name = '販売店B'); sellerB.RecordTypeId = recHanbaiten.id; sellerB.Delete_Flag__c = false; insert sellerB; Oly_TriggerHandler.bypass('PowerBIBaseHandler'); StaticParameter.EscapeSyncOpportunityTrigger = true; StaticParameter.EscapeNFM007Trigger = true; StaticParameter.EscapeOpportunityHpDeptUpdTrigger = true; Oly_TriggerHandler.bypass('AgencyOppUpdHandler'); StaticParameter.EscapeSyncOpportunityTrigger = true; StaticParameter.EscapeOppandStaTrigger = true; System.Test.startTest(); //win Opportunity opp1 = new Opportunity( Name = 'test opp1', StageName = '完了', CurrencyIsoCode = 'USD', CloseDate = Date.today(), AccountId = depart.Id, Closing_Bid_Date__c = Date.today().addDays(-5), Hospital__c = company.Id, Competitor__c = 'A', ConfirmationofAward__c ='OLY中标', OlyNumberHosts__c =1 ); insert opp1; opp1.SAP_Send_OK__c = true; opp1.Authorized_DB_No__c = '123'; opp1.Contract_DB_SalesDept_complite_day__c = Date.today(); opp1.NotesApprovedNo__c = '123'; opp1.OlyNumberHosts__c =2; update opp1; opp1.SAP_Send_OK__c = false; opp1.Reason_Cancel_WIN__c = '1.终止合同'; opp1.OlyNumberHosts__c =3; update opp1; LastbuyProduct__c wqe = new LastbuyProduct__c(); wqe.InquiryCode__c=opp1.Id; wqe.LastbuyQuantity__c=1; wqe.ActualQuantity__c=1; insert wqe; //lt 注释掉 te1 // //招标项目 // Tender_information__c te1 = new Tender_information__c(); // te1.Name = 'TestZhaoBiao'; // insert te1; // opp1.Bidding_Project_Name_Bid__c = te1.Id; // update opp1; //失单 opp1.StageName = '敗戦'; update opp1; //新建询价时,赋值招投标项目,打上标识 // Opportunity opp2 = new Opportunity( // Name = 'test opp1', // StageName = '引合', // CurrencyIsoCode = 'USD', // CloseDate = Date.today(), // AccountId = depart.Id, // Closing_Bid_Date__c = Date.today().addDays(-5), // Hospital__c = company.Id // // ,Competitor__c = 'A' // //,Bidding_Project_Name_Bid__c = te1.Id //lt 20220316 // ); // insert opp2; System.Test.stopTest(); } //2021-05-13 mzy QLM //LastBuy 预留产品 lt 20220315 start @isTest static void TestMethod1() { // Tender_information__c info1 = new Tender_information__c(); // info1.Name = 'TEST001'; // info1.AreaProvince__c = '北京'; // info1.InfoType__c= '3:结果'; // info1.subInfoType__c = '3-5:中标通知'; // info1.OpportunityNum__c = 0; // info1.relativeTime__c =System.now(); // info1.IsReactionOpp__c = false; // insert info1; Opportunity opp = new Opportunity(); opp.Name = 'GZ-SP-NFM007_1'; opp.StageName = '引合'; opp.CloseDate = date.newinstance(2025, 11, 30); //opp.Bidding_Project_Name_Bid__c =info1.id; opp.ConfirmationofAward__c ='竞争对手中标'; opp.Task_createTime__c = date.newinstance(2025, 11, 30); opp.SAP_Send_OK__c = true; insert opp; Product2 pro = new Product2(); pro.Name = 'Testname0316'; pro.LastbuyProductFLG__c = false; insert pro; LastbuyProduct__c lbp = new LastbuyProduct__c(); lbp.Name = 'Test0215'; lbp.ProductName__c = pro.Id; lbp.InquiryCode__c = opp.Id; lbp.effectiveFLG__c = true; insert lbp; List oppList = [Select SAP_Send_OK__c,Id, StageName,StageName__c,ConfirmationofAward__c,DirectLossFLG__c,OwnerId FROM Opportunity Where id =:opp.id]; oppList[0].ConfirmationofAward__c='OLY中标'; update oppList; opp.StageName = '敗戦'; opp.SAP_Send_OK__c = false; update opp; } //LastBuy 预留产品 lt 20220315 end //add start 20220623 @isTest static void test_createTaskByOppConfirmationofAward() { StaticParameter.EscapeContactInsUpdUser = true; StaticParameter.EscapeContactToUser = true; StaticParameter.EscapeAccountTrigger = true; // StaticParameter.EscapeOpportunityownerUpdate = true; // StaticParameter.EventOpportunityPileUpExeFlg = true; // StaticParameter.EscapeOpportunityBefUpdTrigger = true; // StaticParameter.EscapeOpportunityHpDeptUpdTrigger = true; // StaticParameter.EscapeSyncOpportunityTrigger = true; // StaticParameter.EscapeAgencyOpportunityTrigger = true; // StaticParameter.EscapeOppandStaTrigger = true; // StaticParameter.EscapeTenderInformationUpdate = true; // StaticParameter.EscapeZCUpdateTender = true; User user = new User(Test_staff__c = true); user.LastName = '_サンブリッジ'; // user.FirstName = 'う'; user.Alias = 'う'; user.Email = 'olympusTest03@sunbridge.com'; user.Username = 'olympusTest03@sunbridge.com'; user.CommunityNickname = 'う'; user.IsActive = true; user.EmailEncodingKey = 'ISO-2022-JP'; user.TimeZoneSidKey = 'Asia/Tokyo'; user.LocaleSidKey = 'ja_JP'; user.LanguageLocaleKey = 'ja'; user.ProfileId = System.Label.ProfileId_SystemAdmin; user.Job_Category__c = '销售推广'; user.Province__c = '上海市'; user.Use_Start_Date__c = Date.today().addMonths(-6); user.SalesManager__c = UserInfo.getUserId(); user.BuchangApprovalManagerSales__c = UserInfo.getUserId(); user.JingliApprovalManager__c = UserInfo.getUserId(); user.BuchangApprovalManager__c = UserInfo.getUserId(); user.ZongjianApprovalManager__c = UserInfo.getUserId(); Profile p = [select id from Profile where id =:System.Label.ProfileId_SystemAdmin]; String loginId = UserInfo.getUserId(); User sys = [select id from User where Id = :loginId]; User u1 = new User(Test_staff__c = true); u1.LastName = '123'; // u1.FirstName = '2'; u1.Batch_User__c = true; u1.Alias = '2'; u1.Email = 'youchang@prec-tech.com'; u1.Username = 'test_user1@olympus.com.cn.tenopplink'; u1.CommunityNickname = 'あ1'; u1.IsActive = true; u1.EmailEncodingKey = 'ISO-2022-JP'; u1.TimeZoneSidKey = 'Asia/Tokyo'; u1.LocaleSidKey = 'ja_JP'; u1.LanguageLocaleKey = 'ja'; u1.ProfileId = p.id; u1.Job_Category__c = '销售服务'; u1.Province__c = '東京'; u1.IsActive = true; User u2 = new User(Test_staff__c = true); u2.LastName = '_サンブリッジ'; // u2.FirstName = 'い'; u2.Batch_User__c = true; u2.Alias = 'い'; u2.Email = 'youchang1@prec-tech.com'; u2.Username = 'test_user2@olympus.com.cn.tenopplink1'; u2.CommunityNickname = 'い'; u2.IsActive = true; u2.EmailEncodingKey = 'ISO-2022-JP'; u2.TimeZoneSidKey = 'Asia/Tokyo'; u2.LocaleSidKey = 'ja_JP'; u2.LanguageLocaleKey = 'ja'; u2.ProfileId = p.id; u2.Job_Category__c = '销售推广'; u2.Province__c = '東京'; u2.IsActive = true; insert u2; 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; } StaticParameter.EscapeOpportunityBefUpdTrigger = true; StaticParameter.EscapeSyncOpportunityTrigger = true; StaticParameter.EscapeNFM007Trigger = true; StaticParameter.EscapeOpportunityHpDeptUpdTrigger = true; StaticParameter.EscapeOpportunityownerUpdate = true; StaticParameter.EscapeTOLinkTrigger = true; StaticParameter.EscapeEventTrigger = true; System.runAs(new User(Id = Userinfo.getUserId())) { insert user; insert u1; // テストデータ Account company = new Account(); company.RecordTypeId = rectCo[0].Id; company.Name = '测试医院'; 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 section1 = new Account(); section1.RecordTypeId = rectSct[0].Id; section1.Name = '测试医院 消化科 消化科'; section1.Department_Class_Label__c = '消化科'; section1.ParentId = company.Id; section1.Hospital_Department_Class__c = company.Id; insert section1; Account depart = new Account(); depart.RecordTypeId = rectDpt[0].Id; depart.Name = '*'; depart.Department_Name__c = 'NFM007TestDepart'; depart.ParentId = section.Id; depart.Department_Class__c = section.Id; depart.Hospital__c = company.Id; insert depart; // 插入招标项目1 Tender_information__c info1 = new Tender_information__c(); info1.Name = 'TEST001'; info1.AreaProvince__c = '北京'; info1.InfoType__c= '3:结果'; info1.subInfoType__c = '3-5:中标通知'; info1.OpportunityNum__c = 0; info1.OwnerId = u1.Id; info1.InfoOwner__c = u2.Id; info1.relativeTime__c =System.now(); info1.IsReactionOpp__c = false; insert info1; 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-NFM007_1'; // opp.Trade__c = '内貿'; opp.StageName = '引合'; opp.ConfirmationofAward__c='OLY中标'; opp.CloseDate = date.newinstance(2025, 11, 30); opp.OwnerId = u1.id; //opp.Bidding_Project_Name_Bid__c =info1.id; insert opp; //Lost_cancel_report__c lcr =new Lost_cancel_report__c(); //lcr.Opportunity__c = opp.id; //lcr.Report_Status__c = '提交'; //insert lcr; // 中标任务 String winBiddingTask_TaskId = Schema.SObjectType.task__c.getRecordTypeInfosByDeveloperName().get('winBiddingTask').getRecordTypeId(); Task__c tempTask = new Task__c(); tempTask.RecordTypeId = winBiddingTask_TaskId; tempTask.taskDifferent__c = '被动任务'; tempTask.taskStatus__c = '02 接受'; //任务状态2 tempTask.assignee__c = opp.OwnerId; //被分配者 tempTask.account__c = opp.AccountId; tempTask.Name = '中标结果确认:' ;//+ info1.TenderManageCode__c; //招标项目.SFDC编码 tempTask.OwnerId = opp.OwnerId; //所有人 tempTask.OpportunityId__c = opp.Id; tempTask.Tender_information_Task__c = info1.Id; //招标项目 tempTask.ConfirmDate__c = Date.today(); StaticParameter.EscapeTaskcTrigger = true; insert tempTask; StaticParameter.EscapeTaskcTrigger = false; System.Test.startTest(); // List oppList = [Select SAP_Send_OK__c,Bidding_Project_Name_Bid__c,Id, StageName,StageName__c,ConfirmationofAward__c,DirectLossFLG__c,OwnerId FROM Opportunity Where id =:opp.id]; // OpportunityTrigger.isFirst =true; // oppList[0].ConfirmationofAward__c='竞争对手中标'; // update oppList; opp.Department_Class__c = section1.id; opp.ConfirmationofAward__c ='竞争对手中标'; //opp.StageName = '削除'; OpportunityTrigger.isFirst =true; //opp.OwnerId = Userinfo.getUserId(); update opp; Tender_Opportunity_Link__c BlinksList = new Tender_Opportunity_Link__c(); BlinksList.Opportunity__c = opp.Id; BlinksList.CurrencyIsoCode = 'CNY'; BlinksList.IsRelated__c = false; BlinksList.Tender_information__c = info1.Id; insert BlinksList; //List oppList1 = [Select SAP_Send_OK__c,Bidding_Project_Name_Bid__c,Id, StageName,StageName__c,ConfirmationofAward__c,DirectLossFLG__c,OwnerId FROM Opportunity Where id =:oppList[0].id]; //OpportunityTrigger.isFirst =true; //oppList1[0].ConfirmationofAward__c='竞争对手中标'; //oppList1[0].OwnerId = u2.id; //update oppList1; System.Test.stopTest(); } } //end start 20220623 @isTest static void test_method_three() { //医院 List rectHp = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'Agency']; if (rectHp.size() == 0) { return; } Profile p = [select Id from Profile where id =:System.Label.ProfileId_SystemAdmin]; User hpOwner = new User(Test_staff__c = true, LastName = 'hp', Alias = 'hp', Work_Location__c = '北京', CommunityNickname = 'hpOwner', Email = 'olympus_hpowner@sunbridge.com', Username = 'olympus_hpowner@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id); User thisUser = [select Id from User where Id = :UserInfo.getUserId() ]; System.runAs ( thisUser ){ insert hpOwner; // 省 Address_Level__c al = new Address_Level__c(); al.Name = '广东省'; al.Level1_Code__c = 'CN-99'; al.Level1_Sys_No__c = '999999'; insert al; // 市 Address_Level2__c al2 = new Address_Level2__c(); al2.Level1_Code__c = 'CN-99'; al2.Level1_Sys_No__c = '999999'; al2.Level1_Name__c = '广东省'; al2.Name = '深圳市'; al2.Level2_Code__c = 'CN-9999'; al2.Level2_Sys_No__c = '9999999'; al2.Address_Level__c = al.id; insert al2; Account hp = new Account(RecordTypeId = rectHp[0].Id, Name = 'hp', OwnerId = thisUser.Id); hp.Name = 'test hospital'; hp.FSE_GI_Main_Leader__c = thisUser.Id; hp.FSE_SP_Main_Leader__c = thisUser.Id; hp.State_Master__c = al.id; hp.City_Master__c = al2.id; insert hp; OCM_Management_Province__c mp1 = new OCM_Management_Province__c(); mp1.Name = '深圳'; mp1.Province__c = '广东省'; mp1.Window1__c = hpOwner.Id; mp1.ET_DataWindow__c = hpOwner.Id; mp1.ET_BusinessWindow__c = hpOwner.Id; mp1.ET_Assistant1__c = hpOwner.Id; mp1.ET_Assistant2__c = hpOwner.Id; mp1.ENG_DataWindow__c = hpOwner.Id; mp1.ENG_BusinessWindow__c = hpOwner.Id; mp1.ETShareOpp__c = hpOwner.Id; mp1.ENGShareOpp__c = hpOwner.Id; mp1.ENG_Assistant1__c = hpOwner.Id; mp1.ENG_Assistant2__c = hpOwner.Id; insert mp1; Opportunity opp = new Opportunity(); opp.Name='aiueo'; opp.StageName='引合'; opp.Trade__c = '注残'; opp.CurrencyIsoCode = 'CNY'; opp.Estimation_List_Price__c = 100; opp.Wholesale_Price__c = 101; opp.Dealer_Final_Price__c = 102; opp.OCM_Agent1_Price__c = 103; opp.Stocking_Price__c = 104; opp.Estimation_No__c = '105'; opp.Estimation_Name__c = '106'; opp.Estimation_Id__c = '107'; opp.Opp_order_Type__c ='ET'; opp.SAP_Province__c = '广东省'; opp.Fixed_Check__c =true; opp.Close_Forecasted_Date__c = date.today().addMonths(1); opp.CloseDate = date.today().addMonths(1); opp.Stock_apply_status__c ='申请中'; opp.Configuration_Suggestion__c = '无建议'; insert opp; Opportunity opp1 = new Opportunity(); opp1.Name='aiueo'; opp1.StageName = '注残'; opp1.Trade__c = '内貿'; opp1.Close_Forecasted_Date__c = date.today().addMonths(1); opp1.CloseDate = date.today().addMonths(1); opp1.CurrencyIsoCode = 'CNY'; opp1.Estimation_List_Price__c = 100; opp1.Wholesale_Price__c = 101; opp1.Dealer_Final_Price__c = 102; opp1.OCM_Agent1_Price__c = 103; opp1.Stocking_Price__c = 104; opp1.Estimation_No__c = '105'; opp1.Estimation_Name__c = '106'; opp1.Estimation_Id__c = '107'; opp1.Opp_order_Type__c ='ENG'; opp1.SAP_Province__c = '广东省'; opp1.Fixed_Check__c =true; insert opp1; // 共享计划创建 OpportunityShare oppshare = new OpportunityShare(); oppshare.RowCause= 'Manual';//手动 oppshare.OpportunityId = opp.id; oppshare.UserOrGroupId = hpOwner.Id; oppshare.OpportunityAccessLevel = 'Read';//编辑 insert oppshare; OpportunityShare oppshare1 = new OpportunityShare(); oppshare1.RowCause= 'Manual';//手动 oppshare1.OpportunityId = opp1.id; oppshare1.UserOrGroupId = hpOwner.Id; oppshare1.OpportunityAccessLevel = 'Read';//编辑 insert oppshare1; } } }