+ Start a Discussion
muromuromuromuro 

Apexの実行順序について(プロセスビルダー、トリガ)

お世話になっております。

商談の下にカスタムオブジェクトAとB(A・B間にリレーションなし)と、商談とはリレーションがないカスタムオブジェクトCとD(Cが親の主従関係、A・Bとはリレーションなし)があります。
これらのオブジェクトに対して、2つの動作があります。

1.Aにレコードを作成すると、商談を元にCを、Bを元にDを作成する(プロセスビルダーからApexクラス呼び出し)。
2.Aにレコードを作成すると、Bの値を更新する(Apexトリガ、After Insert)

当初、1.で作成されたCとDが2.の影響を受けていなかったので、これらは1.→2.の順で動作していました。
今回、処理2.のコードを改修することになり、ガバナ制限的にも問題のあるコードだったので、同様の動作を制限にかからないように書き直しました。
すると、処理内容はほぼ変わらないはずなのですが、1.で作成されたCとDが2.で更新した後の値となっており、2.→1.の順に動作するようになってしまいました。

Apexの動作順序を考えるとトリガ→プロセスビルダーなので2.→1.が正しい気もするのですが、だとすれば今まで1.→2.の順で動作していた理由がわかりません。業務的には1.→2.が理想です。

この逆転してしまった順番を、トリガを元に戻さずに1.→2.に戻すにはどうすればよいでしょうか。
また、当初1.→2.の順に動作する理由も開設いただければと思います。

以上、よろしくお願いいたします。
Taiki YoshikawaTaiki Yoshikawa
実際にどのように変更されているのかわからないため推測ですが、おそらく保存処理の順番が変更前と異なっていると思います。System.debug処理で処理が想定通りに進んでいるかチェックしていくしかなさそうです。
muromuromuromuro
失礼いたしました。
こちらコードになります。

2.トリガ(変更前)
trigger sCustomObjectAMsgUp on CustomObjectA__c (after update, after insert ,after delete) {
    System.debug(CustomObjectAMsgUpHandler.isRecursion);
    if(CustomObjectAMsgUpHandler.isRecursion){
        return;
    }else{
        CustomObjectAMsgUpHandler.isRecursion = true;
        CustomObjectAMsgUpHandler.CustomObjectAMsgUp(Trigger.newMap, Trigger.oldMap);
    }
    /*string oppid ='';	
    boolean Approveflg =false;
    string stDiscountApproveStatus = '';
    if (Trigger.isDelete) {
        For (CustomObjectA__c o :trigger.old ){
            oppid = o.OpportunityId__c;
        }
    }else{
        For (CustomObjectA__c n :trigger.new ){
            oppid = n.OpportunityId__c;
            if(n.DiscountApproveStatus__c=='承認済'){
                Approveflg=True;
                stDiscountApproveStatus=n.DiscountApproveStatus__c; 
            }
        }
    }
    
    System.debug( ' CustomObjectAMsgUp ★1'+ oppid );
    // メッセージ表示へ
    //OpportunityMessage ms = new OpportunityMessage();
    //ms.MessageOut(oppid);
    
    AggregateResult ar = [SELECT count(Id) oppcount 
                          FROM CustomObjectA__c WHERE OpportunityId__c=:oppid ];
    
    Opportunity opp = [SELECT Id,Message__c,DiscountApprove__c
                       FROM Opportunity WHERE Id=:oppid LIMIT 1];
    if(Approveflg){
        	opp.DiscountApproveStatus__c = stDiscountApproveStatus;
    }
    if((double)ar.get('oppcount') == 0 ){
        
        //if(opp.DiscountApprove__c == True){
        //    opp.Message__c = '特価申請が必要です。';
        //}else{
        opp.Message__c = '';
        //}
    }else{
        if(opp.DiscountApprove__c == True){
            opp.Message__c = '※商談製品明細の編集及び新規作成はできません。';
        }else{
            opp.Message__c = '';
        }
    }   
    
    try { 
       update opp;
    } catch (DmlException e) {
        System.debug('OpportunityMessage Opportunity Update Error: ' + e.getMessage());
    }
    
    System.debug( '★2' + oppid);
    // 採用フラグチェックへ 
    if (!Trigger.isinsert) { 
        //CustomObjectAAdoptPush daap = new CustomObjectAAdoptPush();
        //daap.set(oppid);
        //
        boolean aflg =false;
        // 採用フラグが立った特価申請の特価商談製品明細をコピー
        // 採用フラグが立っているものを検索
        System.debug( '★★★★1:'+ oppid );
        for(CustomObjectA__c da : [SELECT Id, Name
                                      from CustomObjectA__c
                                      where OpportunityId__c =:oppid
                                      and Adopt__c = True LIMIT 1]
           ){
               System.debug( '★★★★2:'+ da.id );
               
               aflg = True;
               // あれば特価商談を読み込み
               CustomObjectC__c opp2 = [SELECT Id, Name ,DistributorId__c,DiscountApproveStatus__c
                                      from CustomObjectC__c
                                      where CustomObjectAId__c =:da.id LIMIT 1];
               
               System.debug( '★★★★3:'+ opp2.id );
               // 特価商談製品明細をよみ商談製品明細に指定項目をコピー
               for(CustomObjectD__c ops : [SELECT 
                                                   Id,
                                                   CustomObjectBId__c,
                                                   DistiBuyPrice2__c,
                                                   ContractMonths__c                                        
                                                   from CustomObjectD__c
                                                   where CustomObjectCId__c =:opp2.id and CustomObjectBId__c != Null and  IsDeleted = false])
               {
                   System.debug( '★★★★4:'+ da.id );
                   // 商談製品明細を更新
                   CustomObjectB__c dai = [SELECT 
                                                ID,                                        
                                                DistiBuyPrice2__c,
                                                ContractMonths__c
                                                from CustomObjectB__c
                                                where id =:ops.CustomObjectBId__c LIMIT 1];
                   dai.DistiBuyPrice2__c = ops.DistiBuyPrice2__c;
                   dai.ContractMonths__c = ops.ContractMonths__c;
                   System.debug( '★★★★4A:'+ da.id );
                   try { 
                       update dai;
                   } catch (DmlException e) {
                       System.debug('CustomObjectAAdoptChk CustomObjectA Update Error: ' + e.getMessage());
                   }                    
               }
               System.debug( '★★★★5:'+ oppid );
               Opportunity opp =[SELECT Id, Name ,DistributorId__c,DiscountApproveStatus__c
                                 from Opportunity
                                 where id =:oppid LIMIT 1];
               opp.DistributorId__c = opp2.DistributorId__c;
               opp.DiscountApproveStatus__c = opp2.DiscountApproveStatus__c;
               try { 
                   update opp;
               } catch (DmlException e) {
                   System.debug('CustomObjectAAdoptChk Opportunity Update Error: ' + e.getMessage());
               }        
           }
        if (!aflg){
            System.debug( '★★★★6:'+ oppid );
            
            // 商談製品明細の値引後ディストリビュータ販売単価と数量2をリセット
            for(CustomObjectB__c ops : [SELECT id,DistiBuyPrice2__c,Quantity2__c
                                             FROM CustomObjectB__c WHERE OpportunityId__c=:oppid] )
            { 
                ops.DistiBuyPrice2__c = Null;
                ops.Quantity2__c =Null;
                try { 
                    update ops;
                } catch (DmlException e) {
                    System.debug('OpportunityBfUp CustomObjectB__c Update Error: ' + e.getMessage());
                }
            }    
        }
    }
}

2.トリガハンドラー(変更後、トリガに直接同様の処理を記述しても順序変わらず)
public with sharing class CustomObjectAMsgUpHandler {
    public static Boolean isRecursion = false;
    public static void CustomObjectAMsgUp(Map<Id, CustomObjectA__c> newDisAppMap, Map<Id, CustomObjectA__c> oldDisAppMap){
        List<CustomObjectA__c> insertedDisAppList = new List<CustomObjectA__c>();
        List<CustomObjectA__c> beforeUpdateDisAppList = new List<CustomObjectA__c>();
        List<CustomObjectA__c> afterUpdateDisAppList = new List<CustomObjectA__c>();
        List<CustomObjectA__c> deletedDisAppList = new List<CustomObjectA__c>();
        Set<Id> oppIdSet = new Set<Id>();
        List<Id> approvedDisAppIdList = new List<Id>();

        for(CustomObjectA__c newDisApp: newDisAppMap.values()){
            if(oldDisAppMap != null && oldDisAppMap.containsKey(newDisApp.Id)){
                afterUpdateDisAppList.add(newDisApp);
                beforeUpdateDisAppList.add(oldDisAppMap.get(newDisApp.Id));
            }else{
                insertedDisAppList.add(newDisApp);
            }
            oppIdSet.add(newDisApp.OpportunityId__c);
            if(newDisApp.DiscountApproveStatus__c == '承認済'){
                approvedDisAppIdList.add(newDisApp.Id);
            }
        }

        if(oldDisAppMap != null){
            for(CustomObjectA__c oldDisApp: oldDisAppMap.values()){
                if(!insertedDisAppList.contains(oldDisApp) && !beforeUpdateDisAppList.contains(oldDisApp) && !afterUpdateDisAppList.contains(oldDisApp)){
                    deletedDisAppList.add(oldDisApp);
                    oppIdSet.add(oldDisApp.OpportunityId__c);
                }
            }
        }

        List<AggregateResult> arList = new List<AggregateResult>([SELECT COUNT(Id) oppCount, OpportunityId__c FROM CustomObjectA__c GROUP BY OpportunityId__c HAVING OpportunityId__c IN: oppIdSet]);
        Map<Id, Opportunity> oppMap = new Map<Id, Opportunity>([SELECT Id, Message__c, DiscountApprove__c, DiscountApproveStatus__c FROM Opportunity WHERE Id IN: oppIdSet]);
        List<Opportunity> updateOppList = new List<Opportunity>();

        for(AggregateResult ar: arList){
            Opportunity tempOpp = new Opportunity();
            tempOpp = oppMap.get((Id)ar.get('OpportunityId__c'));
            if((double)ar.get('oppCount') != 0 && tempOpp.DiscountApprove__c == true){
                tempOpp.Message__c = '※商談製品明細の編集及び新規作成はできません。';
            }else{
                tempOpp.Message__c = '';
            }

            if(approvedDisAppIdList.contains((Id)ar.get('Id'))){
                tempOpp.DiscountApproveStatus__c = '承認済';
            }

            updateOppList.add(tempOpp);
        }

        if(updateOppList.size() > 0){
            update updateOppList;
        }

        Map<Id, CustomObjectA__c> adoptedDaMap = new Map<Id, CustomObjectA__c>([SELECT Id, Name, OpportunityId__c, IsLimitedAmount__c FROM CustomObjectA__c WHERE OpportunityId__c IN: oppIdSet AND Adopt__c = 
        TRUE]);
        
        Map<Id, CustomObjectC__c> opp2Map = new Map<Id, CustomObjectC__c>([SELECT Id, Name, DistributorId__c, DiscountApproveStatus__c FROM CustomObjectC__c WHERE CustomObjectAId__c IN: adoptedDaMap.keySet()]);
        
        Map<Id, CustomObjectD__c> opsMap = new Map<Id, CustomObjectD__c>([SELECT Id, CustomObjectBId__c, DistiBuyPrice2__c, ContractMonths__c FROM CustomObjectD__c WHERE 
        CustomObjectCId__c IN: opp2Map.keySet() AND CustomObjectBId__c != null AND IsDeleted = false]);
        
        Map<Id, Id> opsOppSKUItemIdMap = new Map<Id, Id>();
        
        for(CustomObjectD__c ops: opsMap.values()){
            opsOppSKUItemIdMap.put(ops.Id, ops.CustomObjectBId__c);
        }

        Map<Id, CustomObjectB__c> daiMap = new Map<Id, CustomObjectB__c>([SELECT Id, DistiBuyPrice2__c, ContractMonths__c FROM CustomObjectB__c WHERE Id IN: opsOppSKUItemIdMap.values()]);

        Map<Id, Opportunity> oppMap2 = new Map<Id, Opportunity>([SELECT Id, Name, DistributorId__c, DiscountApproveStatus__c FROM Opportunity WHERE Id IN: oppIdSet]);

        List<CustomObjectB__c> updateDaiList = new List<CustomObjectB__c>();
        List<Opportunity> updateOppList2 = new List<Opportunity>();
        List<Id> limitedDaOppIdList = new List<Id>();
        for(Id oppId: oppIdSet){
            if(adoptedDaMap != null && adoptedDaMap.size() != 0 && adoptedDaMap.get(oppId) != null){
                if(adoptedDaMap.get(oppId).Adopt__c){
                    if(opp2Map != null && opp2Map.size() != 0 && opp2Map.get(adoptedDaMap.get(oppId).Id) != null){
                        if(opsMap != null && opsMap.size() != 0 && opsMap.get(adoptedDaMap.get(oppId).Id).Id != null){
                            if(daiMap != null && daiMap.size() != 0 && daiMap.get(opsOppSKUItemIdMap.get(opp2Map.get(adoptedDaMap.get(oppId).Id).Id)) != null){
                                CustomObjectB__c tempDai = daiMap.get(opsOppSKUItemIdMap.get(opp2Map.get(adoptedDaMap.get(oppId).Id).Id));
                                tempDai.DistiBuyPrice2__c = opsMap.get(adoptedDaMap.get(oppId).Id).DistiBuyPrice2__c;
                                tempDai.ContractMonths__c = opsMap.get(adoptedDaMap.get(oppId).Id).ContractMonths__c;
                                updateDaiList.add(tempDai);
                            }
                        }
                    }
                }

                Opportunity tempOpp = oppMap2.get(oppId);
                tempOpp.DistributorId__c = opp2Map.get(adoptedDaMap.get(oppId).Id).DistributorId__c;
                tempOpp.DiscountApproveStatus__c = opp2Map.get(adoptedDaMap.get(oppId).Id).DiscountApproveStatus__c;
                updateOppList2.add(tempOpp);

            }
        }
        
        Set<Id> limitedDaOppIdSet = new Set<Id>();
        for(CustomObjectA__c da: newDisAppMap.values()){
            if(!da.Adopt__c && da.IsLimitedAmount__c){
                limitedDaOppIdSet.add(da.OpportunityId__c);
            }
        }

        if(limitedDaOppIdSet != null && limitedDaOppIdSet.size() != 0){
            List<CustomObjectB__c> limitedDaiList = new List<CustomObjectB__c>([SELECT Id, DistiBuyPrice2__c, Quantity2__c, OpportunityId__c FROM CustomObjectB__c WHERE OpportunityId__c IN: 
            limitedDaOppIdSet]);
            Map<Id, List<CustomObjectB__c>> limitedDaiMap = new Map<Id, List<CustomObjectB__c>>();
            for(CustomObjectB__c limitedDai: limitedDaiList){
                if(!limitedDaiMap.containsKey(limitedDai.OpportunityId__c)){
                    limitedDaiMap.put(limitedDai.OpportunityId__c, new List<CustomObjectB__c>());
                }
                List<CustomObjectB__c> tempLimitedDaiList = limitedDaiMap.get(limitedDai.OpportunityId__c);
                tempLimitedDaiList.add(limitedDai);
                limitedDaiMap.put(limitedDai.OpportunityId__c, tempLimitedDaiList);
            }

            for(Id oppId: limitedDaOppIdSet){
                List<CustomObjectB__c> tempDaiList = limitedDaiMap.get(oppId);
                for(CustomObjectB__c tempDai: tempDaiList){
                    tempDai.DistiBuyPrice2__c = null;
                    tempDai.Quantity2__c = null;
                    updateDaiList.add(tempDai);
                }
            }
        }

        if(updateDaiList.size() > 0){
            update updateDaiList;
        }
        if(updateOppList2.size() > 0){
            update updateOppList2;
        }
    }
}

1.クラス
public class OpportunityMake01 {
   @InvocableMethod(label='特価商談作成')
    public static List<String> getCustomObjectAIds(List<String> disid) {
        // 特価申請を読み込み ----------------------------------------------
        CustomObjectA__c disapp = [SELECT
                                      Id,
                                      Name,
                                      CreatedDate,
                                      CreatedById,
                                      LastModifiedDate,
                                      LastModifiedById,
                                      SystemModstamp,
                                      OpportunityId__c,
                                      Reason__c,
                                      DiscountApproveUser__c,
                                      IsLimitedAmount__c, //2018-12-06追記
                                      Adopt__c,
                                      DiscountApproveStatus__c
                                      FROM CustomObjectA__c
                                      WHERE Id=:disid
                                      LIMIT 1];

        // 特価申請の運用担当者を読み込み ディストリビュータIDを取得 ---------
        OperationUser__c opu = [SELECT
                                      Distributor__c,
                                	  User__c
                                      FROM OperationUser__c
                                      WHERE Id=:disapp.DiscountApproveUser__c
                                      LIMIT 1];

        // 商談を読み込み ---------------------------------------------------
        Opportunity opp = [SELECT
                           Id,
                           Name,
                           AccountId,
                           Description,
                           StageName,
                           Amount,
                           Probability,
                           TotalOpportunityQuantity,
                           CloseDate,
                           Type,
                           NextStep,
                           LeadSource,
                           IsClosed,
                           IsWon,
                           ForecastCategory,
                           ForecastCategoryName,
                           CampaignId,
                           HasOpportunityLineItem,
                           Pricebook2Id,
                           OwnerId,
                           CreatedDate,
                           CreatedById,
                           LastModifiedDate,
                           LastModifiedById,
                           SystemModstamp,
                           LastActivityDate,
                           FiscalQuarter,
                           FiscalYear,
                           Fiscal,
                           LastViewedDate,
                           LastReferencedDate,
                           SyncedQuoteId,
                           HasOpenActivity,
                           HasOverdueTask,
                           Budget_Confirmed__c,
                           Discovery_Completed__c,
                           ROI_Analysis_Completed__c,
                           DiscountApprove__c,
                           PreviousDeailId__c,
                           GEO__c,
                           Channel__c,
                           DiscountApproveStatus__c,
                           BPwSalesRepId__c,
                           PartnerId__c,
                           PartnerSalesRepId__c,
                           DistributorId__c,
                           ResellerId__c,
                           MSPId__c,
                           MSP_RepId__c,
                           Fiscal_Year__c,
                           Fiscal_Quarter__c,
                           Fiscal_Month__c,
                           Fiscal_Period__c,
                           Loss_Reason__c,
                           Competitor__c,
                           CaseStudyReference__c,
                           DeailId__c,
                           CustomObjectBCount__c,
                           ExpectedRevenue,
                           IsPrivate,
                           QuotationId__c
                           FROM Opportunity
                           WHERE Id=:disapp.OpportunityId__c
                           LIMIT 1];

        // 特価商談作成 ------------------------------------------------
        CustomObjectC__c newOpp2 	= new CustomObjectC__c(
            Reason__c					= disapp.Reason__c,
            //Name						= '(特価)' + opp.Name ,
            OpportunityId__c			= opp.id,
            OpportunityName__c			= opp.Name,
            CustomObjectAId__c		= disapp.id,
            AccountId__c				= opp.AccountId,
            Type__c                     = opp.Type ,
            CampaignId__c               = opp.CampaignId ,
            Budget_Confirmed__c         = opp.Budget_Confirmed__c ,
            Discovery_Completed__c      = opp.Discovery_Completed__c ,
            ROI_Analysis_Completed__c   = opp.ROI_Analysis_Completed__c ,
            CloseDate__c                = opp.CloseDate ,
            StageName__c                = opp.StageName ,
            Probability__c              = opp.Probability ,
            Amount__c                   = opp.Amount ,// < ---------------------------
            TotalOpportunityQuantity__c = opp.TotalOpportunityQuantity ,
            CustomObjectBCount__c  = opp.CustomObjectBCount__c ,
            DeailId__c                  = opp.DeailId__c ,
            PreviousDeailId__c          = opp.PreviousDeailId__c ,
            Competitor__c               = opp.Competitor__c , // < ---------------
            Loss_Reason__c              = opp.Loss_Reason__c ,
            CaseStudyReference__c       = opp.CaseStudyReference__c ,
            DiscountApprove__c          = opp.DiscountApprove__c ,
            DiscountApproveStatus__c    = opp.DiscountApproveStatus__c ,// < ---------
            OwnerId						= opu.User__c,
            ForecastCategoryName__c     = opp.ForecastCategoryName ,
            // 販売ルート ------------------------------------
            GEO__c                      = opp.GEO__c ,
            Channel__c                  = opp.Channel__c ,
            BPwSalesRepId__c            = opp.BPwSalesRepId__c ,
            PartnerId__c                = opp.PartnerId__c ,
            PartnerSalesRepId__c        = opp.PartnerSalesRepId__c ,
            DistributorId__c            = opu.Distributor__c , // < -------------
            ResellerId__c               = opp.ResellerId__c ,
            MSPId__c                    = opp.MSPId__c ,
            MSP_RepId__c                = opp.MSP_RepId__c ,
            // 追加情報   -------------------------------------
            NextStep__c                 = opp.NextStep ,
            LeadSource__c               = opp.LeadSource ,
            Description__c				= opp.Description ,
            // 他 ---------------------------------------------
            Fiscal_Year__c              = opp.Fiscal_Year__c ,
            Fiscal_Quarter__c           = opp.Fiscal_Quarter__c ,
            Fiscal_Month__c             = opp.Fiscal_Month__c ,
            Fiscal_Period__c            = opp.Fiscal_Period__c
            // システム情報 (書き換え不可) -------------------
            //CreatedById                 	= opp.CreatedById ,
            //LastModifiedById            	= opp.LastModifiedById ,
            // ページ内非表示項目 ----------------------------
            //SyncedQuoteId            		= opp.SyncedQuoteId ,
            //QuotationId__c              	= opp.QuotationId__c,
            //ContractId__c					= opp.ContractId,
            // 未使用項目 ------------------------------------
            //Pricebook2Id__c             	= opp.Pricebook2Id ,
            //ExpectedRevenue__c			= opp.ExpectedRevenue ,
            //IsPrivate__c					= opp.IsPrivate
        );
        if(disapp.IsLimitedAmount__c){ //2018-12-06追記 特価商談の場合
        	newOpp2.Name = '(特価)' + opp.Name; //商談名に'(特価)'を追加
        	newOpp2.IsLimitedAmount__c = true;
        }else{ //そうでない場合
        	newOpp2.Name = '(その他)' + opp.Name; //商談名に'(その他)'を追加
        	newOpp2.IsLimitedAmount__c = false;
        }

        try {
            insert newOpp2;
        } catch (DmlException e) {
            System.debug('CustomObjectC Insert Error: ' + e.getMessage());
        }

        // 見積明細行の作成 ----------------------------------------------------------
        if(opp.CustomObjectBCount__c >= 1){
            for(CustomObjectB__c ops : [SELECT
                                             Id,
                                             IsDeleted,
                                             Name,
                                             CreatedDate,
                                             CreatedById,
                                             LastModifiedDate,
                                             LastModifiedById,
                                             SystemModstamp,
                                             OpportunityId__c,
                                             SKUId__c,
                                             StandardProductDescription__c,
                                             Package__c,
                                             SKUGroup2__c,
                                             PackageSKU__c,
                                             ItemDescription__c,
                                             SKU__c,
                                             Quantity1__c,
                                             Unit1__c,
                                             Unit2__c,
                                             Quantity2__c,
                                             MSRP__c,
                                             Discount__c,
                                             UserBuyPrice__c,
                                             UserBuyPriceTotal__c,
                                             DistiBuyPriceRate__c,
                                             DistiBuyPrice__c,
                                             DistiBuyPriceTotal__c,
                                             EffectiveDate1__c,
                                             EffectiveDate2__c,
                                             DistiBuyPrice2__c,
                                             DistiBuyPriceRate2__c,
                                             ContractYears__c,
                                             ContractMonths__c
                                             FROM CustomObjectB__c
                                             WHERE 	OpportunityId__c =:opp.Id and IsDeleted = False]
               ){
                   CustomObjectD__c newDisApp = New CustomObjectD__c(
                       Name                 			= ops.Name,
                       CustomObjectCId__c               	= newOpp2.Id,
                       SKU__c                          	= ops.SKU__c,
                       CustomObjectBId__c			= ops.id,
                       ItemDescription__c              	= ops.ItemDescription__c,
                       EffectiveDate1__c               	= ops.EffectiveDate1__c,
                       EffectiveDate2__c               	= ops.EffectiveDate2__c,
                       Unit1__c                        	= ops.Unit1__c,
                       Quantity1__c                    	= ops.Quantity1__c,
                       SKUGroup2__c                    	= ops.SKUGroup2__c,
                       SKUId__c                        	= ops.SKUId__c,
                       Unit2__c                        	= ops.Unit2__c,
                       Quantity2__c                    	= ops.Quantity2__c,
                       MSRP__c                         	= ops.MSRP__c,
                       UserBuyPriceTotal__c            	= ops.UserBuyPriceTotal__c,
                       ContractYears__c                	= ops.ContractYears__c,
                       ContractMonths__c               	= ops.ContractMonths__c,
                       DistiBuyPrice2__c               	= ops.DistiBuyPrice2__c,
                       Package__c						= ops.Package__c


                       //DistiBuyPriceRate__c           = ops.DistiBuyPriceRate__c,
                       //DistiBuyPriceRate2__c			= ops.DistiBuyPriceRate2__c,
                       //Discount__c 					= ops.Discount__c,
                       //DistiBuyPrice__c 				= ops.DistiBuyPrice__c
                   );
                   System.debug(ops);
                   System.debug(newDisApp);
                   try {
                       insert newDisApp;
                   } catch (DmlException e) {
                       System.debug('CustomObjectD Insert Error: ' + e.getMessage());
                   }
               }

        }

        return disid;
    }
}

変更前のトリガはガバナ制限に抵触しやすいコード(forループ内でDML処理・SOQLクエリを実施)のため、意図的に処理の場所を変更しております。